feat: Parse special keywords as functions (current_user, user, etc) (#561)

* feat: Parse special keywors as functions (current_user, user, etc)

* explain special field
This commit is contained in:
Dmitry Patsura 2022-08-11 15:30:06 +03:00 committed by GitHub
parent b6e36ad760
commit 54a29e872d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 111 additions and 17 deletions

View file

@ -1400,6 +1400,7 @@ fn test_composite_value() {
)))],
over: None,
distinct: false,
special: false
}))))
}),
select.projection[0]
@ -1542,6 +1543,52 @@ fn parse_declare() {
pg_and_generic().verified_stmt("DECLARE \"SQL_CUR0x7fa44801bc00\" BINARY INSENSITIVE SCROLL CURSOR WITH HOLD FOR SELECT * FROM table_name LIMIT 2222");
}
#[test]
fn parse_current_functions() {
let sql = "SELECT CURRENT_CATALOG, CURRENT_USER, SESSION_USER, USER";
let select = pg_and_generic().verified_only_select(sql);
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("CURRENT_CATALOG")]),
args: vec![],
over: None,
distinct: false,
special: true,
}),
expr_from_projection(&select.projection[0])
);
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("CURRENT_USER")]),
args: vec![],
over: None,
distinct: false,
special: true,
}),
expr_from_projection(&select.projection[1])
);
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("SESSION_USER")]),
args: vec![],
over: None,
distinct: false,
special: true,
}),
expr_from_projection(&select.projection[2])
);
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("USER")]),
args: vec![],
over: None,
distinct: false,
special: true,
}),
expr_from_projection(&select.projection[3])
);
}
#[test]
fn parse_fetch() {
pg_and_generic().verified_stmt("FETCH 2048 IN \"SQL_CUR0x7fa44801bc00\"");