Redshift: CREATE TABLE ... (LIKE ..)#1967
Merged
iffyio merged 2 commits intoapache:mainfrom Aug 16, 2025
Merged
Conversation
iffyio
reviewed
Jul 26, 2025
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||
| pub enum CreateTableLikeKind { | ||
| Parenthesized(CreateTableLike), | ||
| NotParenthesized(CreateTableLike), |
Contributor
There was a problem hiding this comment.
Suggested change
| NotParenthesized(CreateTableLike), | |
| Plain(CreateTableLike), |
Thinking we can do similar to e.g. CreateTableOptions, so that NotParenthesized doesn't become ambiguous if there happens to be a third variant in the future
Comment on lines
+10128
to
+10147
| /// Specifies how to create a new table based on an existing table's schema. | ||
| /// | ||
| /// Not parenthesized: | ||
| /// '''sql | ||
| /// CREATE TABLE new LIKE old ... | ||
| /// ''' | ||
| /// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-table#label-create-table-like) | ||
| /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_like) | ||
| /// | ||
| /// Parenthesized: | ||
| /// '''sql | ||
| /// CREATE TABLE new (LIKE old ...) | ||
| /// ''' | ||
| /// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html) | ||
| #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||
| pub enum CreateTableLikeKind { | ||
| Parenthesized(CreateTableLike), | ||
| NotParenthesized(CreateTableLike), |
Contributor
There was a problem hiding this comment.
Suggested change
| /// Specifies how to create a new table based on an existing table's schema. | |
| /// | |
| /// Not parenthesized: | |
| /// '''sql | |
| /// CREATE TABLE new LIKE old ... | |
| /// ''' | |
| /// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-table#label-create-table-like) | |
| /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_like) | |
| /// | |
| /// Parenthesized: | |
| /// '''sql | |
| /// CREATE TABLE new (LIKE old ...) | |
| /// ''' | |
| /// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html) | |
| #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | |
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | |
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | |
| pub enum CreateTableLikeKind { | |
| Parenthesized(CreateTableLike), | |
| NotParenthesized(CreateTableLike), | |
| /// Specifies how to create a new table based on an existing table's schema. | |
| /// | |
| /// '''sql | |
| /// CREATE TABLE new LIKE old ... | |
| /// ''' | |
| #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | |
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | |
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | |
| pub enum CreateTableLikeKind { | |
| /// '''sql | |
| /// CREATE TABLE new (LIKE old ...) | |
| /// ''' | |
| /// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html) | |
| Parenthesized(CreateTableLike), | |
| /// '''sql | |
| /// CREATE TABLE new LIKE old ... | |
| /// ''' | |
| /// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-table#label-create-table-like) | |
| /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_like) | |
| NotParenthesized(CreateTableLike), |
Thinking something like this to document each variant with its example?
| /// CREATE TABLE new (LIKE old ...) | ||
| /// ''' | ||
| /// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html) | ||
| fn supports_create_table_like_in_parens(&self) -> bool { |
Contributor
There was a problem hiding this comment.
Suggested change
| fn supports_create_table_like_in_parens(&self) -> bool { | |
| fn supports_create_table_like_parenthesized(&self) -> bool { |
| let like = if self.parse_keyword(Keyword::LIKE) || self.parse_keyword(Keyword::ILIKE) { | ||
| self.parse_object_name(allow_unquoted_hyphen).ok() | ||
| // Try to parse `CREATE TABLE new (LIKE old [{INCLUDING | EXCLUDING} DEFAULTS])` or `CREATE TABLE new LIKE old` | ||
| let like = if self.dialect.supports_create_table_like_in_parens() |
Contributor
There was a problem hiding this comment.
Can we pull the logic out to a function like maybe_parse_create_table_like()? since it now adds a bit of code to the existing function
257f7d3 to
aedcce9
Compare
iffyio
approved these changes
Aug 16, 2025
Contributor
iffyio
left a comment
There was a problem hiding this comment.
LGTM! Thanks @yoavcloud!
cc @alamb
ayman-sigma
pushed a commit
to sigmacomputing/sqlparser-rs
that referenced
this pull request
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for Redshift
CREATE TABLE new_table (LIKE parent_table [ { INCLUDING | EXCLUDING } DEFAULTS ])