Skip to content

Commit

Permalink
fix: at time zone with func in pg
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Dec 3, 2024
1 parent 97235a8 commit 2669cc6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
14 changes: 14 additions & 0 deletions test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 2669cc6

Please sign in to comment.