public inbox for [email protected]
help / color / mirror / Atom feedFrom: Zsolt Parragi <[email protected]>
To: jian he <[email protected]>
Cc: Vik Fearing <[email protected]>
Cc: David G. Johnston <[email protected]>
Cc: Corey Huinker <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Subject: Re: implement CAST(expr AS type FORMAT 'template')
Date: Mon, 30 Mar 2026 23:17:52 +0100
Message-ID: <CAN4CZFNeCfLzt5g90vf_Dw5BKW2u-QhVKo369XbO-vXYq4ci5g@mail.gmail.com> (raw)
In-Reply-To: <CACJufxFVMYuVz63DteEjbMdvx2neoYcwSRb5vhO-03Tzx=B8Jw@mail.gmail.com>
References: <CACJufxGqm7cYQ5C65Eoh1z-f+aMdhv9_7V=NoLH_p6uuyesi6A@mail.gmail.com>
<[email protected]>
<CACJufxF4OW=x2rCwa+ZmcgopDwGKDXha09qTfTpCj3QSTG6Y9Q@mail.gmail.com>
<[email protected]>
<CACJufxEH-8UPdbPoUoqNRaiOePw+s2W2DG4OpXtoSYDaW30oAg@mail.gmail.com>
<CAKFQuwZXYxPw4wofq+zZ5D7nH0sHDBwr--qku9jWYv7dS+P8RQ@mail.gmail.com>
<CACJufxGTeSnHn7w8r-qoQrqwCFQSC+CbiEthzpHKUd+bPr_0mA@mail.gmail.com>
<[email protected]>
<CACJufxGbsc3g6RZf0rZpKYxffK6vGkc_OsTmX54uS0kFcVBtvA@mail.gmail.com>
<CAKFQuwaG00tsXc2oSQwjdSnPQ=JuH+T8Oeejb3sO5TeqUHsfUQ@mail.gmail.com>
<CADkLM=cvhJBrCj3GV+jXfpb5+U1Z33nsvCXo-=ZkDyaSPbS-1g@mail.gmail.com>
<CAKFQuwYrwM64YnvZ5aL1DEWG50uW-1SrXesSKkmvpxXXrxTW-g@mail.gmail.com>
<[email protected]>
<CACJufxH+soqLj_AuMQj-_jxunVQKX-HBQA_3_3vmV1jTRyZ1hA@mail.gmail.com>
<CACJufxGhOOYnPtmsuVocXVNyx2gB3K68ze67CM4LUqQeW--S8g@mail.gmail.com>
<CAN4CZFNnqWbyk3UNr3XAwtKJooH8LnbDUg-f2JD9z_rG=feT7w@mail.gmail.com>
<CACJufxFVMYuVz63DteEjbMdvx2neoYcwSRb5vhO-03Tzx=B8Jw@mail.gmail.com>
v6 is better, but I found a few more questions:
+select pg_get_viewdef('tcast_v1', true);
+ pg_get_viewdef
+--------------------------------------------------------------------------------------------
+ SELECT CAST( col1 AS date FORMAT 'YYYY-MM-DD'::text) AS to_date,
+
Is that space after "CAST(" intentional?
+ format = coerce_to_target_type(pstate, fmt,
+ exprType(fmt), TEXTOID,
+ exprTypmod(fmt),
+ ccontext, cformat,
+ exprLocation(fmt));
Is exprTypmod(fmt) correct, shouldn't it use -1?
This one also shows a not so userfriendly error:
postgres=# SELECT CAST('hello' AS name FORMAT 'test') ;
2026-03-30 22:12:53.651 UTC [750980] ERROR: function
pg_catalog.to_char(text, text) does not exist
2026-03-30 22:12:53.651 UTC [750980] DETAIL: No function of that name
accepts the given argument types.
2026-03-30 22:12:53.651 UTC [750980] HINT: You might need to add
explicit type casts.
2026-03-30 22:12:53.651 UTC [750980] STATEMENT: SELECT CAST('hello'
AS name FORMAT 'test') ;
ERROR: function pg_catalog.to_char(text, text) does not exist
DETAIL: No function of that name accepts the given argument types.
HINT: You might need to add explicit type casts.
And varchar/bpchar adds details about binary coercible casts:
SELECT CAST('hello' AS bpchar FORMAT 'test') ;
2026-03-30 22:14:12.081 UTC [750980] ERROR: cannot cast type text to
character while using a format template at character 8
2026-03-30 22:14:12.081 UTC [750980] DETAIL: binary coercible type
cast is not supported while using a format template
2026-03-30 22:14:12.081 UTC [750980] STATEMENT: SELECT CAST('hello'
AS bpchar FORMAT 'test') ;
ERROR: cannot cast type text to character while using a format template
LINE 1: SELECT CAST('hello' AS bpchar FORMAT 'test') ;
view thread (56+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: implement CAST(expr AS type FORMAT 'template')
In-Reply-To: <CAN4CZFNeCfLzt5g90vf_Dw5BKW2u-QhVKo369XbO-vXYq4ci5g@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox