mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-28 22:12:24 +00:00
Support create index with clause (#1389)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
d64beea4d4
commit
4d52ee7280
7 changed files with 92 additions and 0 deletions
|
|
@ -45,6 +45,8 @@ pub struct CreateIndex {
|
|||
pub if_not_exists: bool,
|
||||
pub include: Vec<Ident>,
|
||||
pub nulls_distinct: Option<bool>,
|
||||
/// WITH clause: <https://www.postgresql.org/docs/current/sql-createindex.html>
|
||||
pub with: Vec<Expr>,
|
||||
pub predicate: Option<Expr>,
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +85,9 @@ impl Display for CreateIndex {
|
|||
write!(f, " NULLS NOT DISTINCT")?;
|
||||
}
|
||||
}
|
||||
if !self.with.is_empty() {
|
||||
write!(f, " WITH ({})", display_comma_separated(&self.with))?;
|
||||
}
|
||||
if let Some(predicate) = &self.predicate {
|
||||
write!(f, " WHERE {predicate}")?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,4 +86,8 @@ impl Dialect for GenericDialect {
|
|||
fn allow_extract_single_quotes(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn supports_create_index_with_clause(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -509,6 +509,12 @@ pub trait Dialect: Debug + Any {
|
|||
fn allow_extract_single_quotes(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Does the dialect support with clause in create index statement?
|
||||
/// e.g. `CREATE INDEX idx ON t WITH (key = value, key2)`
|
||||
fn supports_create_index_with_clause(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// This represents the operators for which precedence must be defined
|
||||
|
|
|
|||
|
|
@ -162,6 +162,10 @@ impl Dialect for PostgreSqlDialect {
|
|||
fn allow_extract_single_quotes(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn supports_create_index_with_clause(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {
|
||||
|
|
|
|||
|
|
@ -5324,6 +5324,17 @@ impl<'a> Parser<'a> {
|
|||
None
|
||||
};
|
||||
|
||||
let with = if self.dialect.supports_create_index_with_clause()
|
||||
&& self.parse_keyword(Keyword::WITH)
|
||||
{
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let with_params = self.parse_comma_separated(Parser::parse_expr)?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
with_params
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let predicate = if self.parse_keyword(Keyword::WHERE) {
|
||||
Some(self.parse_expr()?)
|
||||
} else {
|
||||
|
|
@ -5340,6 +5351,7 @@ impl<'a> Parser<'a> {
|
|||
if_not_exists,
|
||||
include,
|
||||
nulls_distinct,
|
||||
with,
|
||||
predicate,
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue