Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1766,8 +1766,10 @@ over_clause ::=
func_expr_common_subexpr ::=
'CURRENT_DATE'
| 'CURRENT_SCHEMA'
| 'CURRENT_CATALOG'
| 'CURRENT_TIMESTAMP'
| 'CURRENT_USER'
| 'CURRENT_ROLE'
| 'SESSION_USER'
| 'USER'
| 'CAST' '(' a_expr 'AS' cast_target ')'
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,8 @@ func TestParse2(t *testing.T) {
// Some functions are nearly keywords.
{`SELECT CURRENT_SCHEMA`,
`SELECT current_schema()`},
{`SELECT CURRENT_CATALOG`,
`SELECT current_database()`},
{`SELECT CURRENT_TIMESTAMP`,
`SELECT current_timestamp()`},
{`SELECT CURRENT_DATE`,
Expand All @@ -1066,6 +1068,8 @@ func TestParse2(t *testing.T) {
`SELECT btrim(a, b)`},
{`SELECT CURRENT_USER`,
`SELECT current_user()`},
{`SELECT CURRENT_ROLE`,
`SELECT current_user()`},
{`SELECT SESSION_USER`,
`SELECT current_user()`},
{`SELECT USER`,
Expand Down
13 changes: 12 additions & 1 deletion pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -6356,15 +6356,26 @@ func_expr_common_subexpr:
{
$$.val = &tree.FuncExpr{Func: tree.WrapFunction($1)}
}
// Special identifier current_catalog is equivalent to current_database().
// https://www.postgresql.org/docs/10/static/functions-info.html
| CURRENT_CATALOG
{
$$.val = &tree.FuncExpr{Func: tree.WrapFunction("current_database")}
}
| CURRENT_TIMESTAMP
{
$$.val = &tree.FuncExpr{Func: tree.WrapFunction($1)}
}
| CURRENT_ROLE { return unimplemented(sqllex, "current role") }
| CURRENT_USER
{
$$.val = &tree.FuncExpr{Func: tree.WrapFunction($1)}
}
// Special identifier current_role is equivalent to current_user.
// https://www.postgresql.org/docs/10/static/functions-info.html
| CURRENT_ROLE
{
$$.val = &tree.FuncExpr{Func: tree.WrapFunction("current_user")}
}
| SESSION_USER
{
$$.val = &tree.FuncExpr{Func: tree.WrapFunction("current_user")}
Expand Down