pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem with CAST-ing - am I missing something?
4+ messages / 3 participants
[nested] [flat]
* Problem with CAST-ing - am I missing something?
@ 2023-10-26 00:21 Pól Ua Laoínecháin <linehanp@tcd.ie>
2023-10-26 00:22 ` Re: Problem with CAST-ing - am I missing something? Pól Ua Laoínecháin <linehanp@tcd.ie>
2023-10-26 00:26 ` Re: Problem with CAST-ing - am I missing something? Christophe Pettus <xof@thebuild.com>
0 siblings, 2 replies; 4+ messages in thread
From: Pól Ua Laoínecháin @ 2023-10-26 00:21 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Hi all,
One of the things I really like about PostgreSQL is that it normally
does what I expect it to do - very little cognitive dissonance. But
I'm puzzled by something I came across this evening - took me ages to
figure it out!
I have a table (sample) as follows (code on fiddle:):
CREATE TABLE test (ts, te)
AS VALUES ('2023-10-25 14:33:00'::TIMESTAMPTZ, '2023-10-25
15:56:00'::TIMESTAMPTZ);
Now, this doesn't work:
SELECT (ts, te)::TSTZRANGE FROM test;
but this does:
SELECT TSTZRANGE(ts, te) FROM test;
Bug? Niggle? Can anyone explain to me why this is? To me, it's obvious
what I want to do with the first statement - ideas, pointers, URLs,
whatever welcome.
TIA and rgs,
Pól...
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Problem with CAST-ing - am I missing something?
2023-10-26 00:21 Problem with CAST-ing - am I missing something? Pól Ua Laoínecháin <linehanp@tcd.ie>
@ 2023-10-26 00:22 ` Pól Ua Laoínecháin <linehanp@tcd.ie>
1 sibling, 0 replies; 4+ messages in thread
From: Pól Ua Laoínecháin @ 2023-10-26 00:22 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Sorry folks - fiddle is here: https://dbfiddle.uk/bT4idNK6
Rgs,
Pól...
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Problem with CAST-ing - am I missing something?
2023-10-26 00:21 Problem with CAST-ing - am I missing something? Pól Ua Laoínecháin <linehanp@tcd.ie>
@ 2023-10-26 00:26 ` Christophe Pettus <xof@thebuild.com>
2023-10-26 00:59 ` Re: Problem with CAST-ing - am I missing something? Adrian Klaver <adrian.klaver@aklaver.com>
1 sibling, 1 reply; 4+ messages in thread
From: Christophe Pettus @ 2023-10-26 00:26 UTC (permalink / raw)
To: Pól Ua Laoínecháin <linehanp@tcd.ie>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
> On Oct 25, 2023, at 17:21, Pól Ua Laoínecháin <linehanp@tcd.ie> wrote:
>
> SELECT (ts, te)::TSTZRANGE FROM test;
That syntax doesn't mean what you probably think it does. (ts, te) defines a record type with two fields. PostgreSQL constructs that, and then attempts to apply the cast. There's no conversion path from that to TSTZRANGE, so the system complains. It's imaginable, I guess, that such a path could be added, but the right way to do it is what you do here:
> SELECT TSTZRANGE(ts, te) FROM test;
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Problem with CAST-ing - am I missing something?
2023-10-26 00:21 Problem with CAST-ing - am I missing something? Pól Ua Laoínecháin <linehanp@tcd.ie>
2023-10-26 00:26 ` Re: Problem with CAST-ing - am I missing something? Christophe Pettus <xof@thebuild.com>
@ 2023-10-26 00:59 ` Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 0 replies; 4+ messages in thread
From: Adrian Klaver @ 2023-10-26 00:59 UTC (permalink / raw)
To: Christophe Pettus <xof@thebuild.com>; Pól Ua Laoínecháin <linehanp@tcd.ie>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
On 10/25/23 17:26, Christophe Pettus wrote:
>
>
>> On Oct 25, 2023, at 17:21, Pól Ua Laoínecháin <linehanp@tcd.ie> wrote:
>>
>> SELECT (ts, te)::TSTZRANGE FROM test;
>
> That syntax doesn't mean what you probably think it does. (ts, te) defines a record type with two fields. PostgreSQL constructs that, and then attempts to apply the cast. There's no conversion path from that to TSTZRANGE, so the system complains. It's imaginable, I guess, that such a path could be added, but the right way to do it is what you do here:
>
>> SELECT TSTZRANGE(ts, te) FROM test;
>
Or do something like:
select '[2023-10-25 14:33:00, 2023-10-25 15:56:00)'::TSTZRANGE;
tstzrange
-------------------------------------------------------
["10/25/2023 14:33:00 PDT","10/25/2023 15:56:00 PDT")
per:
https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-IO
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2023-10-26 00:59 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-10-26 00:21 Problem with CAST-ing - am I missing something? Pól Ua Laoínecháin <linehanp@tcd.ie>
2023-10-26 00:22 ` Pól Ua Laoínecháin <linehanp@tcd.ie>
2023-10-26 00:26 ` Christophe Pettus <xof@thebuild.com>
2023-10-26 00:59 ` Adrian Klaver <adrian.klaver@aklaver.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox