diff --git a/pegjs/postgresql.pegjs b/pegjs/postgresql.pegjs index 7cb7cd8d..e72f1948 100644 --- a/pegjs/postgresql.pegjs +++ b/pegjs/postgresql.pegjs @@ -4999,14 +4999,22 @@ func_call }; } / extract_func - / f:scalar_time_func __ up:on_update_current_timestamp? { + / f:scalar_time_func __ l:column_item_suffix? __ up:on_update_current_timestamp? { // => { type: 'function'; name: proc_func_name; over?: on_update_current_timestamp; } - return { + const rest = {} + if (l) { + rest.args = { type: 'expr_list', value: l } + rest.args_parentheses = false + rest.separator = ' ' + } + const result = { type: 'function', name: { name: [{ type: 'origin', value: f }] }, over: up, + ...rest, ...getLocationObject(), } + return result } / name:proc_func_name __ LPAREN __ l:or_and_where_expr? __ RPAREN { // => { type: 'function'; name: proc_func_name; args: expr_list; } diff --git a/test/postgres.spec.js b/test/postgres.spec.js index 9cf03fe2..1aa8a5d6 100644 --- a/test/postgres.spec.js +++ b/test/postgres.spec.js @@ -1714,6 +1714,20 @@ describe('Postgres', () => { 'SELECT * FROM "user" LIMIT (SELECT COUNT(*) / 2 FROM "user")' ] }, + { + title: 'current_timestamp with at time zone', + sql: [ + "select CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AS right_now, my_field FROM my_table;", + `SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AS "right_now", my_field FROM "my_table"` + ] + }, + { + title: 'cast now at time zone', + sql: [ + "select CAST(now() AT TIME ZONE 'UTC' AS TIMESTAMPTZ) AS right_now, my_field FROM my_table;", + `SELECT CAST(now() AT TIME ZONE 'UTC' AS TIMESTAMPTZ) AS "right_now", my_field FROM "my_table"` + ] + }, ] function neatlyNestTestedSQL(sqlList){ sqlList.forEach(sqlInfo => {