Skip to content

Redshift: CREATE TABLE ... (LIKE ..)#1967

Merged
iffyio merged 2 commits intoapache:mainfrom
yoavcloud:redshift_create_table_like
Aug 16, 2025
Merged

Redshift: CREATE TABLE ... (LIKE ..)#1967
iffyio merged 2 commits intoapache:mainfrom
yoavcloud:redshift_create_table_like

Conversation

@yoavcloud
Copy link
Copy Markdown
Contributor

Add support for Redshift CREATE TABLE new_table (LIKE parent_table [ { INCLUDING | EXCLUDING } DEFAULTS ])

Comment thread src/ast/mod.rs Outdated
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum CreateTableLikeKind {
Parenthesized(CreateTableLike),
NotParenthesized(CreateTableLike),
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
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 thread src/ast/mod.rs Outdated
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),
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
/// 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?

Comment thread src/dialect/mod.rs Outdated
/// 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 {
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
fn supports_create_table_like_in_parens(&self) -> bool {
fn supports_create_table_like_parenthesized(&self) -> bool {

Comment thread src/parser/mod.rs Outdated
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()
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 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

@yoavcloud yoavcloud force-pushed the redshift_create_table_like branch from 257f7d3 to aedcce9 Compare August 14, 2025 09:43
@yoavcloud yoavcloud requested a review from iffyio August 14, 2025 09:48
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 b660a3b into apache:main Aug 16, 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