Re: Problem with CAST-ing - am I missing something?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Christophe Pettus <xof(at)thebuild(dot)com>, Pól Ua Laoínecháin <linehanp(at)tcd(dot)ie>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Problem with CAST-ing - am I missing something?
Date: 2023-10-26 00:59:41
Message-ID: 9bc42afd-8be3-47f3-aa7d-20bf12ca39de@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/25/23 17:26, Christophe Pettus wrote:
>
>
>> On Oct 25, 2023, at 17:21, Pól Ua Laoínecháin <linehanp(at)tcd(dot)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(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2023-10-26 09:15:00 Re: Very newbie question
Previous Message Christophe Pettus 2023-10-26 00:26:40 Re: Problem with CAST-ing - am I missing something?