Re: implement CAST(expr AS type FORMAT 'template') - Mailing list pgsql-hackers

From Zsolt Parragi
Subject Re: implement CAST(expr AS type FORMAT 'template')
Date
Msg-id CAN4CZFNnqWbyk3UNr3XAwtKJooH8LnbDUg-f2JD9z_rG=feT7w@mail.gmail.com
Whole thread
In response to Re: implement CAST(expr AS type FORMAT 'template')  (jian he <jian.universality@gmail.com>)
Responses Re: implement CAST(expr AS type FORMAT 'template')
List pgsql-hackers
Hello!

There's some inconsistency in deparse, it displays to_char for intervals:

CREATE VIEW test_interval_format AS
  SELECT CAST('1 year 2 months'::interval AS text FORMAT 'YYYY-MM') AS
fmt_interval;
CREATE VIEW test_timestamp_format AS
  SELECT CAST('2024-01-15 00:00:00'::timestamp AS text FORMAT
'YYYY-MM-DD') AS fmt_timestamp;

SELECT pg_get_viewdef('test_interval_format'::regclass);
SELECT pg_get_viewdef('test_timestamp_format'::regclass);


I also see a similar to_char leak in the error message - wouldn't this
confuse users, as they never wrote to_char?

postgres=# SELECT cast('2012-12-12 12:00'::timetz as text format
'YYYY-MM-DD HH:MI:SS TZ');
2026-03-24 06:27:45.792 UTC [5917] ERROR:  function
pg_catalog.to_char(time with time zone, text) does not exist
2026-03-24 06:27:45.792 UTC [5917] DETAIL:  No function of that name
accepts the given argument types.
2026-03-24 06:27:45.792 UTC [5917] HINT:  You might need to add
explicit type casts.
2026-03-24 06:27:45.792 UTC [5917] STATEMENT:  SELECT cast('2012-12-12
12:00'::timetz as text format 'YYYY-MM-DD HH:MI:SS TZ');
ERROR:  function pg_catalog.to_char(time with time zone, text) does not exist
DETAIL:  No function of that name accepts the given argument types.
HINT:  You might need to add explicit type casts.



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: [PATCH] Fix unexpected loss of DEFERRABLE property after toggling NOT ENFORCED / ENFORCED
Next
From: Pavel Stehule
Date:
Subject: Re: bugfix - fix broken output in expanded aligned format, when data are too short