Skip to content

Commit

Permalink
sql: make current_role an alias for current_user
Browse files Browse the repository at this point in the history
Release note (sql change): `current_role` is recognized as an alias
for `current_user` for better compatibility with PostgreSQL.
  • Loading branch information
knz committed Feb 20, 2018
1 parent e4930b7 commit 2f22fca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,7 @@ func_expr_common_subexpr ::=
| 'CURRENT_CATALOG'
| 'CURRENT_TIMESTAMP'
| 'CURRENT_USER'
| 'CURRENT_ROLE'
| 'SESSION_USER'
| 'USER'
| 'CAST' '(' a_expr 'AS' cast_target ')'
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,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
7 changes: 6 additions & 1 deletion pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -6366,11 +6366,16 @@ func_expr_common_subexpr:
{
$$.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

0 comments on commit 2f22fca

Please sign in to comment.