Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
iffyio merged PR #2127: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2127 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
fmguerreiro commented on code in PR #2127:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2127#discussion_r2633414879
##
tests/sqlparser_postgres.rs:
##
@@ -7492,3 +7494,222 @@ fn parse_create_operator_class() {
)
.is_err());
}
+
+#[test]
+fn parse_create_table_partition_of_range() {
+// RANGE partition with FROM ... TO
+let sql = "CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR
VALUES FROM ('2006-02-01') TO ('2006-03-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("measurement_y2006m02", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("measurement")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(1, from.len());
+assert_eq!(1, to.len());
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-02-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-03-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_range_with_minvalue_maxvalue() {
+// RANGE partition with MINVALUE/MAXVALUE
+let sql =
+"CREATE TABLE orders_old PARTITION OF orders FOR VALUES FROM
(MINVALUE) TO ('2020-01-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_old", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(PartitionBoundValue::MinValue, from[0]);
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2020-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+
+// With MAXVALUE
+let sql =
+"CREATE TABLE orders_new PARTITION OF orders FOR VALUES FROM
('2024-01-01') TO (MAXVALUE)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2024-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+assert_eq!(PartitionBoundValue::MaxValue, to[0]);
+}
+_ => panic!("Expected ForValues::From"),
+},
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_list() {
+// LIST partition
+let sql = "CREATE TABLE orders_us PARTITION OF orders FOR VALUES IN ('US',
'CA', 'MX')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_us", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::In(values)) => {
+assert_eq!(3, values.len());
+}
+_ => panic!("Expected ForValues::In"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_hash() {
+// HASH partition
+let sql = "CREATE TABLE orders_p0 PARTITION OF orders FOR VALUES WITH
(MODULUS 4, REMAINDER 0)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_p0", create_table.name.to_string());
+assert_eq!(
+Some(Object
Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
fmguerreiro commented on code in PR #2127:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2127#discussion_r2633414879
##
tests/sqlparser_postgres.rs:
##
@@ -7492,3 +7494,222 @@ fn parse_create_operator_class() {
)
.is_err());
}
+
+#[test]
+fn parse_create_table_partition_of_range() {
+// RANGE partition with FROM ... TO
+let sql = "CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR
VALUES FROM ('2006-02-01') TO ('2006-03-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("measurement_y2006m02", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("measurement")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(1, from.len());
+assert_eq!(1, to.len());
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-02-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-03-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_range_with_minvalue_maxvalue() {
+// RANGE partition with MINVALUE/MAXVALUE
+let sql =
+"CREATE TABLE orders_old PARTITION OF orders FOR VALUES FROM
(MINVALUE) TO ('2020-01-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_old", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(PartitionBoundValue::MinValue, from[0]);
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2020-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+
+// With MAXVALUE
+let sql =
+"CREATE TABLE orders_new PARTITION OF orders FOR VALUES FROM
('2024-01-01') TO (MAXVALUE)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2024-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+assert_eq!(PartitionBoundValue::MaxValue, to[0]);
+}
+_ => panic!("Expected ForValues::From"),
+},
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_list() {
+// LIST partition
+let sql = "CREATE TABLE orders_us PARTITION OF orders FOR VALUES IN ('US',
'CA', 'MX')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_us", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::In(values)) => {
+assert_eq!(3, values.len());
+}
+_ => panic!("Expected ForValues::In"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_hash() {
+// HASH partition
+let sql = "CREATE TABLE orders_p0 PARTITION OF orders FOR VALUES WITH
(MODULUS 4, REMAINDER 0)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_p0", create_table.name.to_string());
+assert_eq!(
+Some(Object
Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
fmguerreiro commented on code in PR #2127:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2127#discussion_r2633414879
##
tests/sqlparser_postgres.rs:
##
@@ -7492,3 +7494,222 @@ fn parse_create_operator_class() {
)
.is_err());
}
+
+#[test]
+fn parse_create_table_partition_of_range() {
+// RANGE partition with FROM ... TO
+let sql = "CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR
VALUES FROM ('2006-02-01') TO ('2006-03-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("measurement_y2006m02", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("measurement")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(1, from.len());
+assert_eq!(1, to.len());
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-02-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-03-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_range_with_minvalue_maxvalue() {
+// RANGE partition with MINVALUE/MAXVALUE
+let sql =
+"CREATE TABLE orders_old PARTITION OF orders FOR VALUES FROM
(MINVALUE) TO ('2020-01-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_old", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(PartitionBoundValue::MinValue, from[0]);
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2020-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+
+// With MAXVALUE
+let sql =
+"CREATE TABLE orders_new PARTITION OF orders FOR VALUES FROM
('2024-01-01') TO (MAXVALUE)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2024-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+assert_eq!(PartitionBoundValue::MaxValue, to[0]);
+}
+_ => panic!("Expected ForValues::From"),
+},
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_list() {
+// LIST partition
+let sql = "CREATE TABLE orders_us PARTITION OF orders FOR VALUES IN ('US',
'CA', 'MX')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_us", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::In(values)) => {
+assert_eq!(3, values.len());
+}
+_ => panic!("Expected ForValues::In"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_hash() {
+// HASH partition
+let sql = "CREATE TABLE orders_p0 PARTITION OF orders FOR VALUES WITH
(MODULUS 4, REMAINDER 0)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_p0", create_table.name.to_string());
+assert_eq!(
+Some(Object
Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
iffyio commented on code in PR #2127:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2127#discussion_r2629516658
##
tests/sqlparser_postgres.rs:
##
@@ -7492,3 +7494,222 @@ fn parse_create_operator_class() {
)
.is_err());
}
+
+#[test]
+fn parse_create_table_partition_of_range() {
+// RANGE partition with FROM ... TO
+let sql = "CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR
VALUES FROM ('2006-02-01') TO ('2006-03-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("measurement_y2006m02", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("measurement")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(1, from.len());
+assert_eq!(1, to.len());
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-02-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2006-03-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_range_with_minvalue_maxvalue() {
+// RANGE partition with MINVALUE/MAXVALUE
+let sql =
+"CREATE TABLE orders_old PARTITION OF orders FOR VALUES FROM
(MINVALUE) TO ('2020-01-01')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_old", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+assert_eq!(PartitionBoundValue::MinValue, from[0]);
+match &to[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2020-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in to"),
+}
+}
+_ => panic!("Expected ForValues::From"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+
+// With MAXVALUE
+let sql =
+"CREATE TABLE orders_new PARTITION OF orders FOR VALUES FROM
('2024-01-01') TO (MAXVALUE)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => match create_table.for_values {
+Some(ForValues::From { from, to }) => {
+match &from[0] {
+PartitionBoundValue::Expr(Expr::Value(v)) => {
+assert_eq!("'2024-01-01'", v.to_string());
+}
+_ => panic!("Expected Expr value in from"),
+}
+assert_eq!(PartitionBoundValue::MaxValue, to[0]);
+}
+_ => panic!("Expected ForValues::From"),
+},
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_list() {
+// LIST partition
+let sql = "CREATE TABLE orders_us PARTITION OF orders FOR VALUES IN ('US',
'CA', 'MX')";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_us", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName::from(vec![Ident::new("orders")])),
+create_table.partition_of
+);
+match create_table.for_values {
+Some(ForValues::In(values)) => {
+assert_eq!(3, values.len());
+}
+_ => panic!("Expected ForValues::In"),
+}
+}
+_ => panic!("Expected CreateTable"),
+}
+}
+
+#[test]
+fn parse_create_table_partition_of_hash() {
+// HASH partition
+let sql = "CREATE TABLE orders_p0 PARTITION OF orders FOR VALUES WITH
(MODULUS 4, REMAINDER 0)";
+match pg_and_generic().verified_stmt(sql) {
+Statement::CreateTable(create_table) => {
+assert_eq!("orders_p0", create_table.name.to_string());
+assert_eq!(
+Some(ObjectName:
Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
iffyio commented on PR #2127: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2127#issuecomment-3668317804 just in case @fmguerreiro please feel free to re-request review when ready -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
fmguerreiro commented on code in PR #2127:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2127#discussion_r2621400841
##
src/parser/mod.rs:
##
@@ -7833,6 +7833,15 @@ impl<'a> Parser<'a> {
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT,
Keyword::EXISTS]);
let table_name = self.parse_object_name(allow_unquoted_hyphen)?;
+// PostgreSQL PARTITION OF for child partition tables
+let partition_of = if dialect_of!(self is PostgreSqlDialect |
GenericDialect)
+&& self.parse_keywords(&[Keyword::PARTITION, Keyword::OF])
Review Comment:
0bbb684
##
src/parser/mod.rs:
##
@@ -7993,6 +8011,60 @@ impl<'a> Parser<'a> {
}
}
+/// Parse PostgreSQL partition bound specification for PARTITION OF.
+///
+/// Parses: `FOR VALUES partition_bound_spec | DEFAULT`
+///
+///
[PostgreSQL](https://www.postgresql.org/docs/current/sql-createtable.html)
+fn parse_partition_for_values(&mut self) -> Result
{
+if self.parse_keyword(Keyword::DEFAULT) {
+return Ok(ForValues::Default);
+}
+
+self.expect_keywords(&[Keyword::FOR, Keyword::VALUES])?;
+
+if self.parse_keyword(Keyword::IN) {
+// FOR VALUES IN (expr, ...)
+self.expect_token(&Token::LParen)?;
+let values = self.parse_comma_separated(Parser::parse_expr)?;
+self.expect_token(&Token::RParen)?;
+Ok(ForValues::In(values))
+} else if self.parse_keyword(Keyword::FROM) {
+// FOR VALUES FROM (...) TO (...)
+self.expect_token(&Token::LParen)?;
+let from =
self.parse_comma_separated(Parser::parse_partition_bound_value)?;
+self.expect_token(&Token::RParen)?;
+self.expect_keyword(Keyword::TO)?;
+self.expect_token(&Token::LParen)?;
+let to =
self.parse_comma_separated(Parser::parse_partition_bound_value)?;
+self.expect_token(&Token::RParen)?;
+Ok(ForValues::From { from, to })
+} else if self.parse_keyword(Keyword::WITH) {
+// FOR VALUES WITH (MODULUS n, REMAINDER r)
+self.expect_token(&Token::LParen)?;
+self.expect_keyword(Keyword::MODULUS)?;
+let modulus = self.parse_literal_uint()?;
+self.expect_token(&Token::Comma)?;
+self.expect_keyword(Keyword::REMAINDER)?;
+let remainder = self.parse_literal_uint()?;
+self.expect_token(&Token::RParen)?;
+Ok(ForValues::With { modulus, remainder })
+} else {
+self.expected("IN, FROM, or WITH after FOR VALUES",
self.peek_token())
+}
+}
+
+/// Parse a single partition bound value (MINVALUE, MAXVALUE, or
expression).
Review Comment:
0c6857f
##
src/ast/ddl.rs:
##
@@ -3044,6 +3062,76 @@ impl fmt::Display for CreateTable {
}
}
+/// PostgreSQL partition bound specification for PARTITION OF.
Review Comment:
0c6857f
##
src/parser/mod.rs:
##
@@ -7993,6 +8011,60 @@ impl<'a> Parser<'a> {
}
}
+/// Parse PostgreSQL partition bound specification for PARTITION OF.
+///
+/// Parses: `FOR VALUES partition_bound_spec | DEFAULT`
Review Comment:
0c6857f
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] Add PostgreSQL PARTITION OF syntax support [datafusion-sqlparser-rs]
iffyio commented on code in PR #2127:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2127#discussion_r2616149932
##
src/parser/mod.rs:
##
@@ -7833,6 +7833,15 @@ impl<'a> Parser<'a> {
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT,
Keyword::EXISTS]);
let table_name = self.parse_object_name(allow_unquoted_hyphen)?;
+// PostgreSQL PARTITION OF for child partition tables
+let partition_of = if dialect_of!(self is PostgreSqlDialect |
GenericDialect)
+&& self.parse_keywords(&[Keyword::PARTITION, Keyword::OF])
Review Comment:
```suggestion
let partition_of = if self.parse_keywords(&[Keyword::PARTITION,
Keyword::OF])
```
If possible we can skiip the dialect check and let the parser accept the
`PARTITION OF` clause whenever it shows up in an input sql
##
src/parser/mod.rs:
##
@@ -7993,6 +8011,60 @@ impl<'a> Parser<'a> {
}
}
+/// Parse PostgreSQL partition bound specification for PARTITION OF.
+///
+/// Parses: `FOR VALUES partition_bound_spec | DEFAULT`
Review Comment:
```suggestion
/// Parse [ForValues] of a `PARTITION OF` clause.
```
##
src/parser/mod.rs:
##
@@ -7993,6 +8011,60 @@ impl<'a> Parser<'a> {
}
}
+/// Parse PostgreSQL partition bound specification for PARTITION OF.
+///
+/// Parses: `FOR VALUES partition_bound_spec | DEFAULT`
+///
+///
[PostgreSQL](https://www.postgresql.org/docs/current/sql-createtable.html)
+fn parse_partition_for_values(&mut self) -> Result
{
+if self.parse_keyword(Keyword::DEFAULT) {
+return Ok(ForValues::Default);
+}
+
+self.expect_keywords(&[Keyword::FOR, Keyword::VALUES])?;
+
+if self.parse_keyword(Keyword::IN) {
+// FOR VALUES IN (expr, ...)
+self.expect_token(&Token::LParen)?;
+let values = self.parse_comma_separated(Parser::parse_expr)?;
+self.expect_token(&Token::RParen)?;
+Ok(ForValues::In(values))
+} else if self.parse_keyword(Keyword::FROM) {
+// FOR VALUES FROM (...) TO (...)
+self.expect_token(&Token::LParen)?;
+let from =
self.parse_comma_separated(Parser::parse_partition_bound_value)?;
+self.expect_token(&Token::RParen)?;
+self.expect_keyword(Keyword::TO)?;
+self.expect_token(&Token::LParen)?;
+let to =
self.parse_comma_separated(Parser::parse_partition_bound_value)?;
+self.expect_token(&Token::RParen)?;
+Ok(ForValues::From { from, to })
+} else if self.parse_keyword(Keyword::WITH) {
+// FOR VALUES WITH (MODULUS n, REMAINDER r)
+self.expect_token(&Token::LParen)?;
+self.expect_keyword(Keyword::MODULUS)?;
+let modulus = self.parse_literal_uint()?;
+self.expect_token(&Token::Comma)?;
+self.expect_keyword(Keyword::REMAINDER)?;
+let remainder = self.parse_literal_uint()?;
+self.expect_token(&Token::RParen)?;
+Ok(ForValues::With { modulus, remainder })
+} else {
+self.expected("IN, FROM, or WITH after FOR VALUES",
self.peek_token())
+}
+}
+
+/// Parse a single partition bound value (MINVALUE, MAXVALUE, or
expression).
Review Comment:
```suggestion
/// Parse a single [PartitionBoundValue].
```
##
src/ast/ddl.rs:
##
@@ -3044,6 +3062,76 @@ impl fmt::Display for CreateTable {
}
}
+/// PostgreSQL partition bound specification for PARTITION OF.
Review Comment:
```suggestion
/// PostgreSQL partition bound specification for `PARTITION OF`.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
