Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[package]
name = "sqlparser-dsql"
description = "SQL parser fork with Aurora DSQL extensions (CREATE INDEX ASYNC, ALTER TABLE ASYNC, ALTER COLUMN SET STORAGE, order-independent CREATE SEQUENCE, INCLUDE on table constraints). Based on sqlparser 0.62.0."
version = "0.62.3"
version = "0.62.4"
authors = [
"Apache DataFusion <dev@datafusion.apache.org>",
"Amazon Web Services",
Expand Down
5 changes: 4 additions & 1 deletion src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ impl fmt::Display for AlterColumnOperation {
}
}

/// PostgreSQL column storage strategy used by `ALTER COLUMN ... SET STORAGE`.
/// PostgreSQL column storage strategy.
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
Expand Down Expand Up @@ -1935,6 +1935,8 @@ pub enum ColumnOption {
NotNull,
/// `DEFAULT <restricted-expr>`
Default(Expr),
/// `STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }`
Storage(AlterColumnStorage),

/// `MATERIALIZE <expr>`
/// Syntax: `b INT MATERIALIZE (a + 1)`
Expand Down Expand Up @@ -2070,6 +2072,7 @@ impl fmt::Display for ColumnOption {
Null => write!(f, "NULL"),
NotNull => write!(f, "NOT NULL"),
Default(expr) => write!(f, "DEFAULT {expr}"),
Storage(storage) => write!(f, "STORAGE {storage}"),
Materialized(expr) => write!(f, "MATERIALIZED {expr}"),
Ephemeral(expr) => {
if let Some(e) = expr {
Expand Down
2 changes: 2 additions & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ impl Spanned for RaiseStatementValue {
/// Missing spans:
/// - [ColumnOption::Null]
/// - [ColumnOption::NotNull]
/// - [ColumnOption::Storage]
/// - [ColumnOption::Comment]
/// - [ColumnOption::PrimaryKey]
/// - [ColumnOption::Unique]
Expand All @@ -825,6 +826,7 @@ impl Spanned for ColumnOption {
ColumnOption::Null => Span::empty(),
ColumnOption::NotNull => Span::empty(),
ColumnOption::Default(expr) => expr.span(),
ColumnOption::Storage(_) => Span::empty(),
ColumnOption::Materialized(expr) => expr.span(),
ColumnOption::Ephemeral(expr) => expr.as_ref().map_or(Span::empty(), |e| e.span()),
ColumnOption::Alias(expr) => expr.span(),
Expand Down
44 changes: 25 additions & 19 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9349,6 +9349,10 @@ impl<'a> Parser<'a> {
Ok(Some(ColumnOption::Null))
} else if self.parse_keyword(Keyword::DEFAULT) {
Ok(Some(ColumnOption::Default(self.parse_expr()?)))
} else if dialect_of!(self is PostgreSqlDialect | GenericDialect)
&& self.parse_keyword(Keyword::STORAGE)
{
Ok(Some(ColumnOption::Storage(self.parse_column_storage()?)))
} else if dialect_of!(self is ClickHouseDialect| GenericDialect)
&& self.parse_keyword(Keyword::MATERIALIZED)
{
Expand Down Expand Up @@ -10612,25 +10616,7 @@ impl<'a> Parser<'a> {
} else if self.parse_keywords(&[Keyword::DROP, Keyword::DEFAULT]) {
AlterColumnOperation::DropDefault {}
} else if self.parse_keywords(&[Keyword::SET, Keyword::STORAGE]) {
let storage = match self.parse_one_of_keywords(&[
Keyword::PLAIN,
Keyword::EXTERNAL,
Keyword::EXTENDED,
Keyword::MAIN,
Keyword::DEFAULT,
]) {
Some(Keyword::PLAIN) => AlterColumnStorage::Plain,
Some(Keyword::EXTERNAL) => AlterColumnStorage::External,
Some(Keyword::EXTENDED) => AlterColumnStorage::Extended,
Some(Keyword::MAIN) => AlterColumnStorage::Main,
Some(Keyword::DEFAULT) => AlterColumnStorage::Default,
_ => {
return self.expected_ref(
"storage value (PLAIN, EXTERNAL, EXTENDED, MAIN, or DEFAULT)",
self.peek_token_ref(),
)
}
};
let storage = self.parse_column_storage()?;
AlterColumnOperation::SetStorage { storage }
} else if self.parse_keywords(&[Keyword::SET, Keyword::DATA, Keyword::TYPE]) {
self.parse_set_data_type(true)?
Expand Down Expand Up @@ -10809,6 +10795,26 @@ impl<'a> Parser<'a> {
Ok(operation)
}

fn parse_column_storage(&mut self) -> Result<AlterColumnStorage, ParserError> {
match self.parse_one_of_keywords(&[
Keyword::PLAIN,
Keyword::EXTERNAL,
Keyword::EXTENDED,
Keyword::MAIN,
Keyword::DEFAULT,
]) {
Some(Keyword::PLAIN) => Ok(AlterColumnStorage::Plain),
Some(Keyword::EXTERNAL) => Ok(AlterColumnStorage::External),
Some(Keyword::EXTENDED) => Ok(AlterColumnStorage::Extended),
Some(Keyword::MAIN) => Ok(AlterColumnStorage::Main),
Some(Keyword::DEFAULT) => Ok(AlterColumnStorage::Default),
_ => self.expected_ref(
"storage value (PLAIN, EXTERNAL, EXTENDED, MAIN, or DEFAULT)",
self.peek_token_ref(),
),
}
}

fn parse_set_data_type(&mut self, had_set: bool) -> Result<AlterColumnOperation, ParserError> {
let data_type = self.parse_data_type()?;
let using = if self.dialect.supports_alter_column_type_using()
Expand Down
24 changes: 24 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,30 @@ fn parse_alter_table_alter_column_set_storage() {
}
}

#[test]
fn parse_create_table_column_storage() {
for (storage, expected) in [
("PLAIN", AlterColumnStorage::Plain),
("EXTERNAL", AlterColumnStorage::External),
("EXTENDED", AlterColumnStorage::Extended),
("MAIN", AlterColumnStorage::Main),
("DEFAULT", AlterColumnStorage::Default),
] {
let sql = format!("CREATE TABLE tab (payload TEXT STORAGE {storage})");
let statement = pg_and_generic().verified_stmt(&sql);

match statement {
Statement::CreateTable(CreateTable { columns, .. }) => {
assert_eq!(
columns[0].options[0].option,
ColumnOption::Storage(expected)
);
}
_ => unreachable!(),
}
}
}

#[test]
fn parse_alter_table_alter_column_add_generated() {
pg_and_generic()
Expand Down
Loading