mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-29 02:14:07 +00:00
Support general "typed string" literals (#187)
Fixes #168 by enabling `DATE` and other keywords to be used as identifiers when not followed by a string literal. A "typed string" is our term for generalized version of `DATE '...'`/`TIME '...'`/ `TIMESTAMP '...'` literals, represented as `TypedString { data_type, value }` in the AST. Unlike DATE/TIME/TIMESTAMP literals, this is a non-standard extension supported by PostgreSQL at least. This is a port of MaterializeInc/materialize#3146 Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com> Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
This commit is contained in:
parent
34548e890b
commit
6cdd4a146d
5 changed files with 116 additions and 43 deletions
|
@ -413,6 +413,19 @@ fn parse_null_in_select() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_select_with_date_column_name() {
|
||||
let sql = "SELECT date";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&Expr::Identifier(Ident {
|
||||
value: "date".into(),
|
||||
quote_style: None
|
||||
}),
|
||||
expr_from_projection(only(&select.projection)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_escaped_single_quote_string_predicate() {
|
||||
use self::BinaryOperator::*;
|
||||
|
@ -1426,30 +1439,39 @@ fn parse_literal_string() {
|
|||
|
||||
#[test]
|
||||
fn parse_literal_date() {
|
||||
let sql = "SELECT DATE '1999-01-01'";
|
||||
let sql = "SELECT date '1999-01-01'";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::Date("1999-01-01".into())),
|
||||
&Expr::TypedString {
|
||||
data_type: DataType::Date,
|
||||
value: "1999-01-01".into()
|
||||
},
|
||||
expr_from_projection(only(&select.projection)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_literal_time() {
|
||||
let sql = "SELECT TIME '01:23:34'";
|
||||
let sql = "SELECT time '01:23:34'";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::Time("01:23:34".into())),
|
||||
&Expr::TypedString {
|
||||
data_type: DataType::Time,
|
||||
value: "01:23:34".into()
|
||||
},
|
||||
expr_from_projection(only(&select.projection)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_literal_timestamp() {
|
||||
let sql = "SELECT TIMESTAMP '1999-01-01 01:23:34'";
|
||||
let sql = "SELECT timestamp '1999-01-01 01:23:34'";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::Timestamp("1999-01-01 01:23:34".into())),
|
||||
&Expr::TypedString {
|
||||
data_type: DataType::Timestamp,
|
||||
value: "1999-01-01 01:23:34".into()
|
||||
},
|
||||
expr_from_projection(only(&select.projection)),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue