mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-27 21:49:42 +00:00
allow DateTimeField::Custom with EXTRACT in Postgres (#1394)
This commit is contained in:
parent
7282ce22f9
commit
222b7d127a
6 changed files with 111 additions and 6 deletions
|
|
@ -78,4 +78,12 @@ impl Dialect for GenericDialect {
|
|||
fn support_map_literal_syntax(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn allow_extract_custom(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn allow_extract_single_quotes(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -499,6 +499,16 @@ pub trait Dialect: Debug + Any {
|
|||
fn describe_requires_table_keyword(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Returns true if this dialect allows the `EXTRACT` function to words other than [`Keyword`].
|
||||
fn allow_extract_custom(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Returns true if this dialect allows the `EXTRACT` function to use single quotes in the part being extracted.
|
||||
fn allow_extract_single_quotes(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// This represents the operators for which precedence must be defined
|
||||
|
|
|
|||
|
|
@ -154,6 +154,14 @@ impl Dialect for PostgreSqlDialect {
|
|||
Precedence::Or => OR_PREC,
|
||||
}
|
||||
}
|
||||
|
||||
fn allow_extract_custom(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn allow_extract_single_quotes(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {
|
||||
|
|
|
|||
|
|
@ -158,6 +158,14 @@ impl Dialect for SnowflakeDialect {
|
|||
fn describe_requires_table_keyword(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn allow_extract_custom(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn allow_extract_single_quotes(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse snowflake create table statement.
|
||||
|
|
|
|||
|
|
@ -1970,15 +1970,14 @@ impl<'a> Parser<'a> {
|
|||
Keyword::TIMEZONE_HOUR => Ok(DateTimeField::TimezoneHour),
|
||||
Keyword::TIMEZONE_MINUTE => Ok(DateTimeField::TimezoneMinute),
|
||||
Keyword::TIMEZONE_REGION => Ok(DateTimeField::TimezoneRegion),
|
||||
_ if dialect_of!(self is SnowflakeDialect | GenericDialect) => {
|
||||
_ if self.dialect.allow_extract_custom() => {
|
||||
self.prev_token();
|
||||
let custom = self.parse_identifier(false)?;
|
||||
Ok(DateTimeField::Custom(custom))
|
||||
}
|
||||
_ => self.expected("date/time field", next_token),
|
||||
},
|
||||
Token::SingleQuotedString(_) if dialect_of!(self is SnowflakeDialect | GenericDialect) =>
|
||||
{
|
||||
Token::SingleQuotedString(_) if self.dialect.allow_extract_single_quotes() => {
|
||||
self.prev_token();
|
||||
let custom = self.parse_identifier(false)?;
|
||||
Ok(DateTimeField::Custom(custom))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue