public inbox for [email protected]
help / color / mirror / Atom feedFrom: Francisco Olarte <[email protected]>
To: Igal Sapir <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: Passing a dynamic interval to generate_series()
Date: Mon, 1 Jul 2024 09:20:11 +0200
Message-ID: <CA+bJJbw=5g2iGHGKUhY+a45fghT=3eCyn2c3CtTNj-tzj+YGcA@mail.gmail.com> (raw)
In-Reply-To: <CA+zig08QbXa9zkLJuK_QDiBon1Wq6T1gqwyr_4xCcY-i2=ePhA@mail.gmail.com>
References: <CA+zig0-suhFUeS7xcJyZ=4HDFXJ3Kn2adXo3B4zHUzDFgMscCw@mail.gmail.com>
<[email protected]>
<CA+zig08QbXa9zkLJuK_QDiBon1Wq6T1gqwyr_4xCcY-i2=ePhA@mail.gmail.com>
Hi Igal:
On Mon, 1 Jul 2024 at 01:17, Igal Sapir <[email protected]> wrote:
> I actually did test the expression that I posted, but it might be casting it twice. While your examples that you wrote show 1 month correctly:
> SELECT (interval '1 ' || 'month');
> ?column? |
> -------------+
> 00:00:01month|
No, it does not, try it like this:
s=> with a(x) as ( SELECT (interval '1 ' || 'month')) select x,
pg_typeof(x) from a;
x | pg_typeof
---------------+-----------
00:00:01month | text
(1 row)
And you'll understand what is happening. Cast to interval has higher
priority then concatenation, so you are selecting a 1 second interval,
casting it to text, '00:00:01', adding 'month' at end.
This can also be noticed because month output would not use ':' and have spaces:
s=> with a(x) as ( SELECT '001.00MONTHS'::interval) select x,
pg_typeof(x) from a;
x | pg_typeof
-------+-----------
1 mon | interval
(1 row)
( I used fractions, uppercase and no spaces on input to show how
interval output normalizes ).
Francisco Olarte.
view thread (3+ messages)
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]
Subject: Re: Passing a dynamic interval to generate_series()
In-Reply-To: <CA+bJJbw=5g2iGHGKUhY+a45fghT=3eCyn2c3CtTNj-tzj+YGcA@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