Skip to content

Commit a453fdb

Browse files
committed
redshift: add support for CREATE VIEW … WITH NO SCHEMA BINDING
1 parent 6cd7b55 commit a453fdb

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

src/ast/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ pub enum Statement {
12821282
cluster_by: Vec<Ident>,
12831283
destination_table: Option<ObjectName>,
12841284
columns_with_types: Vec<ColumnDef>,
1285+
late_binding: bool,
12851286
},
12861287
/// CREATE TABLE
12871288
CreateTable {
@@ -2110,6 +2111,7 @@ impl fmt::Display for Statement {
21102111
cluster_by,
21112112
destination_table,
21122113
columns_with_types,
2114+
late_binding
21132115
} => {
21142116
write!(
21152117
f,
@@ -2135,7 +2137,11 @@ impl fmt::Display for Statement {
21352137
if !cluster_by.is_empty() {
21362138
write!(f, " CLUSTER BY ({})", display_comma_separated(cluster_by))?;
21372139
}
2138-
write!(f, " AS {query}")
2140+
write!(f, " AS {query}")?;
2141+
if *late_binding{
2142+
write!(f, " WITH NO SCHEMA BINDING")?;
2143+
}
2144+
Ok(())
21392145
}
21402146
Statement::CreateTable {
21412147
name,

src/keywords.rs

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ define_keywords!(
109109
BIGINT,
110110
BIGNUMERIC,
111111
BINARY,
112+
BINDING,
112113
BLOB,
113114
BOOLEAN,
114115
BOTH,

src/parser.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,9 @@ impl<'a> Parser<'a> {
28222822
self.expect_keyword(Keyword::AS)?;
28232823
let query = Box::new(self.parse_query()?);
28242824
// Optional `WITH [ CASCADED | LOCAL ] CHECK OPTION` is widely supported here.
2825+
2826+
let late_binding = dialect_of!(self is RedshiftSqlDialect) && self.parse_keywords(&[Keyword::WITH, Keyword::NO, Keyword::SCHEMA, Keyword::BINDING]);
2827+
28252828
Ok(Statement::CreateView {
28262829
name,
28272830
columns,
@@ -2832,6 +2835,7 @@ impl<'a> Parser<'a> {
28322835
cluster_by,
28332836
destination_table,
28342837
columns_with_types,
2838+
late_binding
28352839
})
28362840
}
28372841

tests/sqlparser_common.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -5015,6 +5015,7 @@ fn parse_create_view() {
50155015
cluster_by,
50165016
destination_table,
50175017
columns_with_types,
5018+
late_binding,
50185019
} => {
50195020
assert_eq!("myschema.myview", name.to_string());
50205021
assert_eq!(Vec::<Ident>::new(), columns);
@@ -5025,6 +5026,7 @@ fn parse_create_view() {
50255026
assert_eq!(cluster_by, vec![]);
50265027
assert_eq!(destination_table, None);
50275028
assert_eq!(columns_with_types, vec![]);
5029+
assert_eq!(late_binding, false);
50285030
}
50295031
_ => unreachable!(),
50305032
}
@@ -5067,6 +5069,7 @@ fn parse_create_view_with_columns() {
50675069
cluster_by,
50685070
destination_table,
50695071
columns_with_types,
5072+
late_binding,
50705073
} => {
50715074
assert_eq!("v", name.to_string());
50725075
assert_eq!(columns, vec![Ident::new("has"), Ident::new("cols")]);
@@ -5077,6 +5080,7 @@ fn parse_create_view_with_columns() {
50775080
assert_eq!(cluster_by, vec![]);
50785081
assert_eq!(destination_table, None);
50795082
assert_eq!(columns_with_types, vec![]);
5083+
assert_eq!(late_binding, false);
50805084
}
50815085
_ => unreachable!(),
50825086
}
@@ -5096,6 +5100,7 @@ fn parse_create_or_replace_view() {
50965100
cluster_by,
50975101
destination_table,
50985102
columns_with_types,
5103+
late_binding,
50995104
} => {
51005105
assert_eq!("v", name.to_string());
51015106
assert_eq!(columns, vec![]);
@@ -5106,6 +5111,7 @@ fn parse_create_or_replace_view() {
51065111
assert_eq!(cluster_by, vec![]);
51075112
assert_eq!(destination_table, None);
51085113
assert_eq!(columns_with_types, vec![]);
5114+
assert_eq!(late_binding, false);
51095115
}
51105116
_ => unreachable!(),
51115117
}
@@ -5129,6 +5135,7 @@ fn parse_create_or_replace_materialized_view() {
51295135
cluster_by,
51305136
destination_table,
51315137
columns_with_types,
5138+
late_binding,
51325139
} => {
51335140
assert_eq!("v", name.to_string());
51345141
assert_eq!(columns, vec![]);
@@ -5139,6 +5146,7 @@ fn parse_create_or_replace_materialized_view() {
51395146
assert_eq!(cluster_by, vec![]);
51405147
assert_eq!(destination_table, None);
51415148
assert_eq!(columns_with_types, vec![]);
5149+
assert_eq!(late_binding, false);
51425150
}
51435151
_ => unreachable!(),
51445152
}
@@ -5158,6 +5166,7 @@ fn parse_create_materialized_view() {
51585166
cluster_by,
51595167
destination_table,
51605168
columns_with_types,
5169+
late_binding,
51615170
} => {
51625171
assert_eq!("myschema.myview", name.to_string());
51635172
assert_eq!(Vec::<Ident>::new(), columns);
@@ -5168,6 +5177,7 @@ fn parse_create_materialized_view() {
51685177
assert_eq!(cluster_by, vec![]);
51695178
assert_eq!(destination_table, None);
51705179
assert_eq!(columns_with_types, vec![]);
5180+
assert_eq!(late_binding, false);
51715181
}
51725182
_ => unreachable!(),
51735183
}
@@ -5186,7 +5196,8 @@ fn parse_create_materialized_view_with_cluster_by() {
51865196
with_options,
51875197
cluster_by,
51885198
destination_table,
5189-
columns_with_types
5199+
columns_with_types,
5200+
late_binding,
51905201
} => {
51915202
assert_eq!("myschema.myview", name.to_string());
51925203
assert_eq!(Vec::<Ident>::new(), columns);
@@ -5197,6 +5208,7 @@ fn parse_create_materialized_view_with_cluster_by() {
51975208
assert_eq!(cluster_by, vec![Ident::new("foo")]);
51985209
assert_eq!(destination_table, None);
51995210
assert_eq!(columns_with_types, vec![]);
5211+
assert_eq!(late_binding, false);
52005212
}
52015213
_ => unreachable!(),
52025214
}

tests/sqlparser_redshift.rs

+5
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,8 @@ fn test_sharp() {
280280
fn test_select_ignore_nulls() {
281281
redshift().verified_stmt("SELECT last_value(b) IGNORE NULLS FROM test_data");
282282
}
283+
284+
#[test]
285+
fn test_create_view_late_binding() {
286+
redshift().verified_stmt("CREATE VIEW myevent AS SELECT eventname FROM event WITH NO SCHEMA BINDING");
287+
}

0 commit comments

Comments
 (0)