diff --git a/pegjs/postgresql.pegjs b/pegjs/postgresql.pegjs index c3543f37..a4360f4f 100644 --- a/pegjs/postgresql.pegjs +++ b/pegjs/postgresql.pegjs @@ -3309,8 +3309,8 @@ cast_data_type } column_item_suffix - = 'AT' __ KW_TIME __ 'ZONE'i __ t:quoted_ident_type { - // => [{ type: 'origin'; value: string; }, quoted_ident_type] + = 'AT'i __ KW_TIME __ 'ZONE'i __ t:(quoted_ident_type / column_ref) { + // => [{ type: 'origin'; value: string; }, quoted_ident_type | column_ref] return [ { type: 'origin', diff --git a/test/postgres.spec.js b/test/postgres.spec.js index 35f67ec5..34f8b779 100644 --- a/test/postgres.spec.js +++ b/test/postgres.spec.js @@ -1686,6 +1686,13 @@ describe('Postgres', () => { `SELECT start_time::TIMESTAMP AT TIME ZONE 'UTC' AS "start_time" FROM "my_table"` ] }, + { + title: 'complex at time zone', + sql: [ + 'select date(cast(t.start_time at time zone loc.timezone as timestamptz)) as start_time from my_table t', + 'SELECT date(CAST("t".start_time AT TIME ZONE "loc".timezone AS TIMESTAMPTZ)) AS "start_time" FROM "my_table" AS "t"', + ] + }, { title: 'create index with if not exists', sql: [