mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-29 22:37:17 +00:00
Support TO in CREATE VIEW clause for Clickhouse (#1313)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
f16c1afed0
commit
f3d2f78fb2
7 changed files with 51 additions and 2 deletions
|
|
@ -2029,6 +2029,9 @@ pub enum Statement {
|
|||
if_not_exists: bool,
|
||||
/// if true, has SQLite `TEMP` or `TEMPORARY` clause <https://www.sqlite.org/lang_createview.html>
|
||||
temporary: bool,
|
||||
/// if not None, has Clickhouse `TO` clause, specify the table into which to insert results
|
||||
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/view#materialized-view>
|
||||
to: Option<ObjectName>,
|
||||
},
|
||||
/// ```sql
|
||||
/// CREATE TABLE
|
||||
|
|
@ -3329,15 +3332,20 @@ impl fmt::Display for Statement {
|
|||
with_no_schema_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
to,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name}",
|
||||
"CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name}{to}",
|
||||
or_replace = if *or_replace { "OR REPLACE " } else { "" },
|
||||
materialized = if *materialized { "MATERIALIZED " } else { "" },
|
||||
name = name,
|
||||
temporary = if *temporary { "TEMPORARY " } else { "" },
|
||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }
|
||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
||||
to = to
|
||||
.as_ref()
|
||||
.map(|to| format!(" TO {to}"))
|
||||
.unwrap_or_default()
|
||||
)?;
|
||||
if let Some(comment) = comment {
|
||||
write!(
|
||||
|
|
|
|||
|
|
@ -4172,6 +4172,14 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
}
|
||||
|
||||
let to = if dialect_of!(self is ClickHouseDialect | GenericDialect)
|
||||
&& self.parse_keyword(Keyword::TO)
|
||||
{
|
||||
Some(self.parse_object_name(false)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let comment = if dialect_of!(self is SnowflakeDialect | GenericDialect)
|
||||
&& self.parse_keyword(Keyword::COMMENT)
|
||||
{
|
||||
|
|
@ -4209,6 +4217,7 @@ impl<'a> Parser<'a> {
|
|||
with_no_schema_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
to,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue