Skip to content

Snowflake: support trailing options in CREATE TABLE #1931

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 4 commits into from
Jul 14, 2025

Conversation

yoavcloud
Copy link
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
/// 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
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 on lines 390 to 393
!self.columns.is_empty()
|| self.query.is_some()
|| self.like.is_some()
|| self.clone.is_some()
Copy link
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
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
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
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
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