-
Notifications
You must be signed in to change notification settings - Fork 630
Redshift: CREATE TABLE ... (LIKE ..) #1967
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
base: main
Are you sure you want to change the base?
Conversation
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||
pub enum CreateTableLikeKind { | ||
Parenthesized(CreateTableLike), | ||
NotParenthesized(CreateTableLike), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
/// 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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
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
Add support for Redshift
CREATE TABLE new_table (LIKE parent_table [ { INCLUDING | EXCLUDING } DEFAULTS ])