diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index f9b58ed32e5c..08d5a0503134 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -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 ')' diff --git a/pkg/sql/parser/parse_test.go b/pkg/sql/parser/parse_test.go index 29e768d34cda..5c9e6495240b 100644 --- a/pkg/sql/parser/parse_test.go +++ b/pkg/sql/parser/parse_test.go @@ -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`, @@ -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`, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 291947a8d95a..01e8e3c07a5e 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -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")}