Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuzz/fuzz_seeds/postgres_niladic_value_functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT CURRENT_ROLE, SYSTEM_USER, CURRENT_SCHEMA, current_schema()
5 changes: 5 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,9 +1628,14 @@ impl<'a> Parser<'a> {
self.prev_token();
Ok(Some(Expr::Value(self.parse_value()?)))
}
// `current_schema()` is also an ordinary function call
Keyword::CURRENT_SCHEMA if self.peek_token_ref().token == Token::LParen => Ok(None),
Keyword::CURRENT_CATALOG
| Keyword::CURRENT_ROLE
| Keyword::CURRENT_SCHEMA
| Keyword::CURRENT_USER
| Keyword::SESSION_USER
| Keyword::SYSTEM_USER
| Keyword::USER
if dialect_of!(self is PostgreSqlDialect | GenericDialect) =>
{
Expand Down
57 changes: 57 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13518,3 +13518,60 @@ fn parse_case_ending_in_end_keyword_is_not_silently_dropped() {
ParserError::ParserError("Expected: end of statement, found: END".to_string())
);
}

#[test]
fn parse_current_role_system_user_current_schema() {
let select =
pg_and_generic().verified_only_select("SELECT CURRENT_ROLE, SYSTEM_USER, CURRENT_SCHEMA");
for (item, name) in
select
.projection
.iter()
.zip(["CURRENT_ROLE", "SYSTEM_USER", "CURRENT_SCHEMA"])
{
assert_eq!(
&Expr::Function(Function {
name: ObjectName::from(vec![Ident::new(name)]),
uses_odbc_syntax: false,
parameters: FunctionArguments::None,
args: FunctionArguments::None,
null_treatment: None,
filter: None,
over: None,
within_group: vec![],
}),
expr_from_projection(item)
);
}

let select = pg_and_generic().verified_only_select("SELECT current_schema()");
assert_eq!(
&Expr::Function(Function {
name: ObjectName::from(vec![Ident::new("current_schema")]),
uses_odbc_syntax: false,
parameters: FunctionArguments::None,
args: FunctionArguments::List(FunctionArgumentList {
duplicate_treatment: None,
args: vec![],
clauses: vec![],
}),
null_treatment: None,
filter: None,
over: None,
within_group: vec![],
}),
expr_from_projection(only(&select.projection))
);

let select = pg_and_generic().verified_only_select(r#"SELECT "current_role""#);
assert_eq!(
&Expr::Identifier(Ident::with_quote('"', "current_role")),
expr_from_projection(only(&select.projection))
);

assert_eq!(
pg().parse_sql_statements("SELECT CURRENT_ROLE()")
.unwrap_err(),
ParserError::ParserError("Expected: end of statement, found: (".to_string())
);
}
Loading