Skip to content

Commit a6211ec

Browse files
authored
Merge pull request #19 from fmguerreiro/fix/matview-with-no-data
feat(parser): parse WITH [NO] DATA on CREATE MATERIALIZED VIEW
2 parents ff7fc3e + d60ebd7 commit a6211ec

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

.worktrees/fix-pr-2307-ci

Lines changed: 0 additions & 1 deletion
This file was deleted.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
[package]
1919
name = "pgmold-sqlparser"
2020
description = "Fork of sqlparser with additional PostgreSQL features (PARTITION OF, SECURITY DEFINER/INVOKER, SET params, EXCLUDE, TEXT SEARCH, AGGREGATE, FOREIGN TABLE/FDW, PUBLICATION, SUBSCRIPTION, ALTER DOMAIN/TRIGGER/EXTENSION, CAST, CONVERSION, LANGUAGE, RULE, STATISTICS, ACCESS METHOD, EVENT TRIGGER, TRANSFORM, SECURITY LABEL, USER MAPPING, TABLESPACE)"
21-
version = "0.60.10"
21+
version = "0.60.11"
2222
authors = ["Filipe Guerreiro <filipe.m.guerreiro@gmail.com>"]
2323
homepage = "https://github.com/fmguerreiro/datafusion-sqlparser-rs"
2424
documentation = "https://docs.rs/pgmold-sqlparser/"

src/ast/ddl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,6 +4364,11 @@ pub struct CreateView {
43644364
pub to: Option<ObjectName>,
43654365
/// MySQL: Optional parameters for the view algorithm, definer, and security context
43664366
pub params: Option<CreateViewParams>,
4367+
/// PostgreSQL: `WITH [NO] DATA` clause on materialized views.
4368+
/// `None` means the clause was absent; `Some(true)` means `WITH DATA`;
4369+
/// `Some(false)` means `WITH NO DATA`.
4370+
/// <https://www.postgresql.org/docs/current/sql-creatematerializedview.html>
4371+
pub with_data: Option<bool>,
43674372
}
43684373

43694374
impl fmt::Display for CreateView {
@@ -4430,6 +4435,11 @@ impl fmt::Display for CreateView {
44304435
if self.with_no_schema_binding {
44314436
write!(f, " WITH NO SCHEMA BINDING")?;
44324437
}
4438+
match self.with_data {
4439+
Some(true) => write!(f, " WITH DATA")?,
4440+
Some(false) => write!(f, " WITH NO DATA")?,
4441+
None => {}
4442+
}
44334443
Ok(())
44344444
}
44354445
}

src/parser/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6645,6 +6645,20 @@ impl<'a> Parser<'a> {
66456645
Keyword::BINDING,
66466646
]);
66476647

6648+
// PostgreSQL: optional WITH [NO] DATA clause on materialized views.
6649+
// pg_dump emits this clause; parse it so corpus schemas round-trip cleanly.
6650+
let with_data = if materialized && self.parse_keyword(Keyword::WITH) {
6651+
if self.parse_keyword(Keyword::NO) {
6652+
self.expect_keyword_is(Keyword::DATA)?;
6653+
Some(false)
6654+
} else {
6655+
self.expect_keyword_is(Keyword::DATA)?;
6656+
Some(true)
6657+
}
6658+
} else {
6659+
None
6660+
};
6661+
66486662
Ok(CreateView {
66496663
or_alter,
66506664
name,
@@ -6663,6 +6677,7 @@ impl<'a> Parser<'a> {
66636677
to,
66646678
params: create_view_params,
66656679
name_before_not_exists,
6680+
with_data,
66666681
})
66676682
}
66686683

0 commit comments

Comments
 (0)