From: | Igal Sapir <igal(at)lucee(dot)org> |
---|---|
To: | pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Passing a dynamic interval to generate_series() |
Date: | 2024-06-30 22:39:26 |
Message-ID: | CA+zig0-suhFUeS7xcJyZ=4HDFXJ3Kn2adXo3B4zHUzDFgMscCw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
I am trying to pass a dynamic interval to generate_series() with date range.
This works as expected, and generates a series with an interval of 1 month:
SELECT generate_series(
date_trunc('month', current_date),
date_trunc('month', current_date + interval '7 month'),
interval '1 month'
)
This works as expected and returns an interval of 1 month:
SELECT ('1 ' || 'month')::interval;
But this throws an error (SQL Error [42601]: ERROR: syntax error at or near
"'1 '"):
SELECT generate_series(
date_trunc('month', current_date),
date_trunc('month', current_date + interval '7 month'),
interval ('1 ' || 'month')::interval
)
And this returns a series with interval of 1 second??
SELECT generate_series(
date_trunc('month', current_date),
date_trunc('month', current_date + interval '7 month'),
(interval '1 ' || 'month')::interval
)
Because this returns an interval of 1 second:
SELECT (interval '1 ' || 'month')::interval;
Is that a bug?
I am able to work around the issue using a CASE statement, but shouldn't it
work simply by concatenating the string with the || operator?
Thank you,
Igal
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2024-06-30 22:51:14 | Re: Passing a dynamic interval to generate_series() |
Previous Message | agharta agharta | 2024-06-28 19:07:21 | Re: A way to optimize sql about the last temporary-related row |