Skip to content

Commit

Permalink
Merge pull request #22828 from knz/20180220-pg-compat
Browse files Browse the repository at this point in the history
sql: additional pg compatibility functions
  • Loading branch information
knz authored Feb 20, 2018
2 parents 5d8a93e + 2f22fca commit b98b8a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit b98b8a7

Please sign in to comment.