@@ -31,7 +31,7 @@ use recursion::RecursionCounter;
31
31
use IsLateral::*;
32
32
use IsOptional::*;
33
33
34
- use crate::ast::helpers::stmt_create_table::{BigQueryTableConfiguration, CreateTableBuilder };
34
+ use crate::ast::helpers::stmt_create_table::{CreateTableBuilder, CreateTableConfiguration };
35
35
use crate::ast::*;
36
36
use crate::dialect::*;
37
37
use crate::keywords::{Keyword, ALL_KEYWORDS};
@@ -5430,11 +5430,7 @@ impl<'a> Parser<'a> {
5430
5430
None
5431
5431
};
5432
5432
5433
- let big_query_config = if dialect_of!(self is BigQueryDialect | GenericDialect) {
5434
- self.parse_optional_big_query_create_table_config()?
5435
- } else {
5436
- Default::default()
5437
- };
5433
+ let create_table_config = self.parse_optional_create_table_config()?;
5438
5434
5439
5435
// Parse optional `AS ( query )`
5440
5436
let query = if self.parse_keyword(Keyword::AS) {
@@ -5519,39 +5515,46 @@ impl<'a> Parser<'a> {
5519
5515
.collation(collation)
5520
5516
.on_commit(on_commit)
5521
5517
.on_cluster(on_cluster)
5522
- .partition_by(big_query_config .partition_by)
5523
- .cluster_by(big_query_config .cluster_by)
5524
- .options(big_query_config .options)
5518
+ .partition_by(create_table_config .partition_by)
5519
+ .cluster_by(create_table_config .cluster_by)
5520
+ .options(create_table_config .options)
5525
5521
.primary_key(primary_key)
5526
5522
.strict(strict)
5527
5523
.build())
5528
5524
}
5529
5525
5530
- /// Parse configuration like partitioning, clustering information during big-query table creation.
5531
- /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_2>
5532
- fn parse_optional_big_query_create_table_config(
5526
+ /// Parse configuration like partitioning, clustering information during the table creation.
5527
+ ///
5528
+ /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_2)
5529
+ /// [PostgreSQL](https://www.postgresql.org/docs/current/ddl-partitioning.html)
5530
+ fn parse_optional_create_table_config(
5533
5531
&mut self,
5534
- ) -> Result<BigQueryTableConfiguration, ParserError> {
5535
- let mut partition_by = None;
5536
- if self.parse_keywords(&[Keyword::PARTITION, Keyword::BY]) {
5537
- partition_by = Some(Box::new(self.parse_expr()?));
5532
+ ) -> Result<CreateTableConfiguration, ParserError> {
5533
+ let partition_by = if dialect_of!(self is BigQueryDialect | PostgreSqlDialect | GenericDialect)
5534
+ && self.parse_keywords(&[Keyword::PARTITION, Keyword::BY])
5535
+ {
5536
+ Some(Box::new(self.parse_expr()?))
5537
+ } else {
5538
+ None
5538
5539
};
5539
5540
5540
5541
let mut cluster_by = None;
5541
- if self.parse_keywords(&[Keyword::CLUSTER, Keyword::BY]) {
5542
- cluster_by = Some(WrappedCollection::NoWrapping(
5543
- self.parse_comma_separated(|p| p.parse_identifier(false))?,
5544
- ));
5545
- };
5546
-
5547
5542
let mut options = None;
5548
- if let Token::Word(word) = self.peek_token().token {
5549
- if word.keyword == Keyword::OPTIONS {
5550
- options = Some(self.parse_options(Keyword::OPTIONS)?);
5551
- }
5552
- };
5543
+ if dialect_of!(self is BigQueryDialect | GenericDialect) {
5544
+ if self.parse_keywords(&[Keyword::CLUSTER, Keyword::BY]) {
5545
+ cluster_by = Some(WrappedCollection::NoWrapping(
5546
+ self.parse_comma_separated(|p| p.parse_identifier(false))?,
5547
+ ));
5548
+ };
5549
+
5550
+ if let Token::Word(word) = self.peek_token().token {
5551
+ if word.keyword == Keyword::OPTIONS {
5552
+ options = Some(self.parse_options(Keyword::OPTIONS)?);
5553
+ }
5554
+ };
5555
+ }
5553
5556
5554
- Ok(BigQueryTableConfiguration {
5557
+ Ok(CreateTableConfiguration {
5555
5558
partition_by,
5556
5559
cluster_by,
5557
5560
options,
0 commit comments