From 6cd7e948f8ef1b382ec5263c62da92df89f86b05 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Mon, 26 Oct 2026 12:10:59 +0900 Subject: [PATCH v2 1/2] Add tests for AT TIME ZONE and similar as FROM-clause functions AT TIME ZONE, AT LOCAL, OVERLAPS and IS NORMALIZED are not function calls in the grammar, so they can be used as a function in FROM only inside a CAST. When the CAST does not change the type, the parser drops it, and the view is printed with the bare expression, which cannot be read back: (LOCALTIMESTAMP AT TIME ZONE 'UTC'::text) atz(atz) (CURRENT_TIME AT TIME ZONE 'UTC'::text) atzt(atzt) (LOCALTIMESTAMP AT LOCAL) atl(atl) ((LOCALTIMESTAMP, LOCALTIMESTAMP) OVERLAPS (LOCALTIMESTAMP, LOCALTIMESTAMP)) o(o) ('foo'::text IS NORMALIZED) isn(isn) ROWS FROM(('foo'::text IS NORMALIZED), now()) rf(rfa, rfb) Extend tt20v with these. The expected output shows the behavior before the fix. The next commit fixes it and updates the output. --- src/test/regress/expected/create_view.out | 50 ++++++++++++++++------- src/test/regress/sql/create_view.sql | 9 +++- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out index 85ffca793f2..dd078eded7b 100644 --- a/src/test/regress/expected/create_view.out +++ b/src/test/regress/expected/create_view.out @@ -1969,22 +1969,42 @@ select * from current_date as d, localtimestamp(3) as t, cast(1+2 as int4) as i4, - cast(1+2 as int8) as i8; + cast(1+2 as int8) as i8, + cast(localtimestamp at time zone 'UTC' as timestamptz) as atz, + cast(current_time at time zone 'UTC' as timetz) as atzt, + cast(localtimestamp at local as timestamptz) as atl, + cast((localtimestamp, localtimestamp) overlaps + (localtimestamp, localtimestamp) as boolean) as o, + cast('foo' is normalized as boolean) as isn, + rows from(cast('foo' is normalized as boolean), now()) as rf(rfa, rfb); select pg_get_viewdef('tt20v', true); - pg_get_viewdef ---------------------------------------------- - SELECT c.c, + - col.col, + - d.d, + - t.t, + - i4.i4, + - i8.i8 + - FROM COALESCE(1, 2) c(c), + - COLLATION FOR ('x'::text) col(col), + - CURRENT_DATE d(d), + - LOCALTIMESTAMP(3) t(t), + - CAST(1 + 2 AS integer) i4(i4), + - CAST((1 + 2)::bigint AS bigint) i8(i8); + pg_get_viewdef +---------------------------------------------------------------------------------------- + SELECT c.c, + + col.col, + + d.d, + + t.t, + + i4.i4, + + i8.i8, + + atz.atz, + + atzt.atzt, + + atl.atl, + + o.o, + + isn.isn, + + rf.rfa, + + rf.rfb + + FROM COALESCE(1, 2) c(c), + + COLLATION FOR ('x'::text) col(col), + + CURRENT_DATE d(d), + + LOCALTIMESTAMP(3) t(t), + + CAST(1 + 2 AS integer) i4(i4), + + CAST((1 + 2)::bigint AS bigint) i8(i8), + + (LOCALTIMESTAMP AT TIME ZONE 'UTC'::text) atz(atz), + + (CURRENT_TIME AT TIME ZONE 'UTC'::text) atzt(atzt), + + (LOCALTIMESTAMP AT LOCAL) atl(atl), + + ((LOCALTIMESTAMP, LOCALTIMESTAMP) OVERLAPS (LOCALTIMESTAMP, LOCALTIMESTAMP)) o(o),+ + ('foo'::text IS NORMALIZED) isn(isn), + + ROWS FROM(('foo'::text IS NORMALIZED), now()) rf(rfa, rfb); (1 row) -- reverse-listing of various special function syntaxes required by SQL diff --git a/src/test/regress/sql/create_view.sql b/src/test/regress/sql/create_view.sql index 82b8d8ab395..45d9a217d79 100644 --- a/src/test/regress/sql/create_view.sql +++ b/src/test/regress/sql/create_view.sql @@ -712,7 +712,14 @@ select * from current_date as d, localtimestamp(3) as t, cast(1+2 as int4) as i4, - cast(1+2 as int8) as i8; + cast(1+2 as int8) as i8, + cast(localtimestamp at time zone 'UTC' as timestamptz) as atz, + cast(current_time at time zone 'UTC' as timetz) as atzt, + cast(localtimestamp at local as timestamptz) as atl, + cast((localtimestamp, localtimestamp) overlaps + (localtimestamp, localtimestamp) as boolean) as o, + cast('foo' is normalized as boolean) as isn, + rows from(cast('foo' is normalized as boolean), now()) as rf(rfa, rfb); select pg_get_viewdef('tt20v', true); -- reverse-listing of various special function syntaxes required by SQL -- 2.54.0 (Apple Git-157)