Skip to content

Fix AS query clause should be after the create table options #1339

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

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

git-hulk
Copy link
Member

According to MySQL[1] and PostgreSQL[2] create table syntax, the AS query should be sit after the table options. But it is parsed before table options include CHARSET and COLLATE, as well as ON COMMIT clause. This PR resolves this issue by moving the position of AS query, and the issue #1274 will be aslo resolved after this PR.

MySQL:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    [(create_definition,...)]
    [table_options]
    [partition_options]
    [IGNORE | REPLACE]
    [AS] query_expression

PostgreSQL:

CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
    [ (column_name [, ...] ) ]
    [ USING method ]
    [ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
    [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
    [ TABLESPACE tablespace_name ]
    AS query
    [ WITH [ NO ] DATA ]

[1] https://dev.mysql.com/doc/refman/8.0/en/create-table.html
[2] https://www.postgresql.org/docs/current/sql-createtableas.html

According to MySQL[1] and PostgreSQL[2] create table syntax,
the AS query should be sit after the table options. But it
is parsed before table options include CHARSET and COLLATE,
as well as ON COMMIT clause. This PR resolves this issue by
moving the position of AS query, and the issue apache#1274 will be
aslo resolved after this PR.

MySQL:

```
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    [(create_definition,...)]
    [table_options]
    [partition_options]
    [IGNORE | REPLACE]
    [AS] query_expression
```

PostgreSQL:

```
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
    [ (column_name [, ...] ) ]
    [ USING method ]
    [ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
    [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
    [ TABLESPACE tablespace_name ]
    AS query
    [ WITH [ NO ] DATA ]
```

[1] https://dev.mysql.com/doc/refman/8.0/en/create-table.html
[2] https://www.postgresql.org/docs/current/sql-createtableas.html
@coveralls
Copy link

coveralls commented Jul 12, 2024

Pull Request Test Coverage Report for Build 9927891212

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 32 of 32 (100.0%) changed or added relevant lines in 4 files are covered.
  • 227 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.005%) to 89.194%

Files with Coverage Reduction New Missed Lines %
tests/sqlparser_postgres.rs 21 87.95%
src/parser/mod.rs 206 93.29%
Totals Coverage Status
Change from base Build 9864598743: 0.005%
Covered Lines: 26858
Relevant Lines: 30112

💛 - Coveralls

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me -- thank you @git-hulk

cc @iffyio

@git-hulk git-hulk requested review from iffyio and alamb July 14, 2024 12:24
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@alamb alamb merged commit 20f7ac5 into apache:main Jul 15, 2024
10 checks passed
@alamb
Copy link
Contributor

alamb commented Jul 15, 2024

Looks good to me -- thank you @git-hulk and @iffyio

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 this pull request may close these issues.

4 participants