Skip to content

Snowflake: support trailing options in CREATE TABLE#1931

Merged
iffyio merged 4 commits intoapache:mainfrom
yoavcloud:sf_create_table_as
Jul 14, 2025
Merged

Snowflake: support trailing options in CREATE TABLE#1931
iffyio merged 4 commits intoapache:mainfrom
yoavcloud:sf_create_table_as

Conversation

@yoavcloud
Copy link
Copy Markdown
Contributor

The code that parses CREATE TABLE in the Snowflake dialect assumed that if the AS, LIKE or CLONE options are used, then no other options can be specified. That is not true, so that restriction is now removed.

For example:
CREATE TEMP TABLE dst AS (SELECT * FROM src) ON COMMIT PRESERVE ROWS

@yoavcloud yoavcloud changed the title Sf create table as Snowflake trailing options in CREATE TABLE Jul 8, 2025
Comment thread src/ast/helpers/stmt_create_table.rs Outdated
/// Returns true if information on the structure of the table
/// to be created was provided to the builder. If not, the
/// statement is invalid.
pub fn has_schema_info(&self) -> bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn has_schema_info(&self) -> bool {
pub(crate) fn has_schema_info(&self) -> bool {

Comment thread src/ast/helpers/stmt_create_table.rs Outdated
Comment on lines +390 to +393
!self.columns.is_empty()
|| self.query.is_some()
|| self.like.is_some()
|| self.clone.is_some()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we add tests covering this behavior? e.g a test that fails when only a query, columns, like etc is provided in a create statement

Comment on lines +1000 to +1019
snowflake()
.parse_sql_statements(
"CREATE TEMP TABLE dst AS (SELECT * FROM src) ON COMMIT PRESERVE ROWS",
)
.unwrap();
snowflake()
.parse_sql_statements("CREATE TEMP TABLE tbl LIKE customers ON COMMIT PRESERVE ROWS;")
.unwrap();
snowflake()
.parse_sql_statements("CREATE TEMP TABLE tbl CLONE customers ON COMMIT PRESERVE ROWS;")
.unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we use verified_stmt here or similar roundtrip assertion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Improved the tests, note Snowflake supports specifying the options either before or after the "source" definition while the SQL output assumes one. Added tests for both options.

@iffyio iffyio changed the title Snowflake trailing options in CREATE TABLE Snowflake: support trailing options in CREATE TABLE Jul 10, 2025
@yoavcloud yoavcloud force-pushed the sf_create_table_as branch from dd8ad08 to 794cdcf Compare July 11, 2025 06:28
@yoavcloud yoavcloud requested a review from iffyio July 11, 2025 07:12
@yoavcloud yoavcloud force-pushed the sf_create_table_as branch from c21ea51 to 3aa41f3 Compare July 11, 2025 09:41
Copy link
Copy Markdown
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! Thanks @yoavcloud!
cc @alamb

@iffyio iffyio merged commit 750a7aa into apache:main Jul 14, 2025
10 checks passed
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Feb 3, 2026
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.

2 participants