Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "Returning" part of DELETE statement. #1527

Closed
LonwoLonwo opened this issue May 6, 2022 · 1 comment · Fixed by #1528
Closed

Support "Returning" part of DELETE statement. #1527

LonwoLonwo opened this issue May 6, 2022 · 1 comment · Fixed by #1528

Comments

@LonwoLonwo
Copy link

Hello!

Our user expecting some problem with DELETE statement with returning clause.
dbeaver/dbeaver#15946

Because delete from t returning *; statement can't be parsed
Please, add support of RETURNING clause in DELETE statement.

Encountered unexpected token: "returning" "RETURNING"
    at line 1, column 15.

Was expecting one of:

    ";"
    "ACTION"
    "ACTIVE"
    "ALGORITHM"
    "ARCHIVE"
    "ARRAY"
    "AS"
    "AT"
    "BYTE"
    "CASCADE"
    "CASE"
    "CAST"
    "CHANGE"
    "CHAR"
    "CHARACTER"
    "CHECKPOINT"
    "COLUMN"
    "COLUMNS"
    "COMMENT"
    "COMMIT"
    "COSTS"
    "CYCLE"
    "DBA_RECYCLEBIN"
    "DESC"
    "DESCRIBE"
    "DISABLE"
    "DISCONNECT"
    "DIV"
    "DO"
    "DUMP"
    "DUPLICATE"
    "ENABLE"
    "END"
    "EXCLUDE"
    "EXTRACT"
    "FALSE"
    "FILTER"
    "FIRST"
    "FLUSH"
    "FN"
    "FOLLOWING"
    "FORMAT"
    "FULLTEXT"
    "HISTORY"
    "INDEX"
    "INSERT"
    "INTERVAL"
    "ISNULL"
    "JSON"
    "KEY"
    "LAST"
    "LEADING"
    "LIMIT"
    "LINK"
    "LOCAL"
    "LOG"
    "MATERIALIZED"
    "NO"
    "NOLOCK"
    "NULLS"
    "OF"
    "OPEN"
    "ORDER"
    "OVER"
    "PARALLEL"
    "PARTITION"
    "PATH"
    "PERCENT"
    "PRECISION"
    "PRIMARY"
    "PRIOR"
    "QUERY"
    "QUIESCE"
    "RANGE"
    "READ"
    "RECYCLEBIN"
    "REGISTER"
    "REPLACE"
    "RESTRICTED"
    "RESUME"
    "ROW"
    "ROWS"
    "SCHEMA"
    "SEPARATOR"
    "SEQUENCE"
    "SESSION"
    "SHUTDOWN"
    "SIBLINGS"
    "SIGNED"
    "SIZE"
    "SKIP"
    "SUSPEND"
    "SWITCH"
    "SYNONYM"
    "SYSTEM"
    "TABLE"
    "TABLESPACE"
    "TEMP"
    "TEMPORARY"
    "TIMEOUT"
    "TO"
    "TOP"
    "TRUE"
    "TRUNCATE"
    "TRY_CAST"
    "TYPE"
    "UNQIESCE"
    "UNSIGNED"
    "USER"
    "USING"
    "VALIDATE"
    "VALUE"
    "VALUES"
    "VIEW"
    "WHERE"
    "XML"
    "ZONE"
    <EOF>
    <K_DATETIMELITERAL>
    <K_DATE_LITERAL>
    <K_NEXTVAL>
    <K_STRING_FUNCTION_NAME>
    <S_CHAR_LITERAL>
    <S_IDENTIFIER>
    <S_QUOTED_IDENTIFIER>

SQL Example
This statement doesn't work.

delete from t returning *;

And Update statement already support returning statement:

update t set a = 1 returning *;

I see that UPDATE supports returning clause, and DELETE statement - don't.

Software Information

  • JSqlParser version - 4.2
  • Database - PostgreSQL
@manticore-projects
Copy link
Contributor

Thank you for reporting, I respond to the original issue and will (try to) provide a patch.

manticore-projects added a commit to manticore-projects/JSqlParser that referenced this issue May 6, 2022
Fixes JSQLParser#1527
Add DELETE... RETURNING ... expression
Simplify INSERT ... RETURNING ... expression
Simply UPDATE ... RETURNING ... expression
wumpz pushed a commit that referenced this issue May 11, 2022
* #1527 DELETE ... RETURNING ...

Fixes #1527
Add DELETE... RETURNING ... expression
Simplify INSERT ... RETURNING ... expression
Simply UPDATE ... RETURNING ... expression

* TSQL Output Clause

According to https://docs.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql?view=sql-server-ver15
Implement Output Clause for INSERT, UPDATE and DELETE
Add Tests according the Microsoft Documentation

* Appease Codacy/PMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants