Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sO3Cx-00C5sm-1g for pgsql-general@arkaria.postgresql.org; Sun, 30 Jun 2024 22:39:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sO3Cv-00DdZm-B2 for pgsql-general@arkaria.postgresql.org; Sun, 30 Jun 2024 22:39:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sO3Cu-00DdZc-Vw for pgsql-general@lists.postgresql.org; Sun, 30 Jun 2024 22:39:41 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sO3Ct-004NBZ-2x for pgsql-general@lists.postgresql.org; Sun, 30 Jun 2024 22:39:40 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-24cbb884377so1475913fac.0 for ; Sun, 30 Jun 2024 15:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lucee.org; s=google; t=1719787177; x=1720391977; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=9MyUSIB6sYd7K2tRjslFzn4bWEHhv/yqloiuVw0GTY8=; b=fo7njWuAX81N8XMwg0W95m7jwz0ziFdPkHcTRFeF/JnjtpwdvsAUcrHsbvpNSaNzFG USyjpb/HeSH8XwlKz4kNtDK3jGHcjE0PO+WFOI4afVz+AAokbgMYNUa/qbo210XPlHnF /xwYVT6tM2fBavyYA2cksSxWxzwq0lZWKWPmr7Oo4tmLjJxoHb9L5MMElwmR0MNARFI6 rmVBxEeKyvL6iWXcaE0o0WMnT/aaFEwuM6g6JzunydB15hzlUQC6K6q23m+GipL/5GN/ qemOlD/gRZdcPW/dBks2j8YPdxIDsgoUPh3ArOH7K2BVlQaL/4WBI8aU78918HaY8YJK Lkgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719787177; x=1720391977; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9MyUSIB6sYd7K2tRjslFzn4bWEHhv/yqloiuVw0GTY8=; b=B54MvdwNk6I0owzk3rhWvGBa3XnBFks5EP/A8vk46tQNU28wYWaItNnnAIFga1m7SP P4dAAOu4lzAeVb3UjUXxqqjtAveFzPz1zcWCTEwqAubLAQWRxMB6aepvQUc78lXdPKSE Db0j3pL9Ick6hKb+NC+DsBOetQFrKkX96dfYtkO7OX3eMq31q2ptvDx8wPp1jHcwqOJI ccYb5kwDg0Jypx2tekNF9W1GnAR6i8vlZQUenP8Xk1APFWUZypakU3K3UDX7wyFWBuHs D1k7184fA07/n4zhA/3DAhx9a/JKJaaTiadk12J0lnyHlSryimXfv7H1ZtLLEV2YKikP kipQ== X-Gm-Message-State: AOJu0Yx04VzaGe+8GtWpqm4XJ+k6Ig8OJVKEY2h0h8m9wJ0jm62uHNWL Q2YOyMqCCf0UsLUFNhiyEZzuarbcxLwLZ8oDTxN1LRimcd1gQgdmmbeNBJLWVik/kQgeqsoNODd 78KpT+Td6Hp7JACaoEed//hwj1UJtOh/9L/cJ+821Y7WvJhJnwwY= X-Google-Smtp-Source: AGHT+IEhlmuReqcVfPDn9tH5ddwmBHQw+hJNmjdRSkekSuWhZww3NkSQ2UBT80IAWlYtMLyFMMGRrFjjzZY4o4sikZ0= X-Received: by 2002:a05:6870:9208:b0:255:2e14:3d9d with SMTP id 586e51a60fabf-25db334c573mr4111977fac.5.1719787177401; Sun, 30 Jun 2024 15:39:37 -0700 (PDT) MIME-Version: 1.0 From: Igal Sapir Date: Sun, 30 Jun 2024 15:39:26 -0700 Message-ID: Subject: Passing a dynamic interval to generate_series() To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000cc7991061c23275d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000cc7991061c23275d Content-Type: text/plain; charset="UTF-8" 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 --000000000000cc7991061c23275d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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(
=C2=A0 =C2=A0 date_t= runc('month', current_date),
=C2=A0 =C2=A0 date_trunc('month= ', current_date + interval '7 month'),
=C2=A0 =C2=A0 interva= l '1 month'
)


This = works as expected and returns an interval of 1 month:

<= div>SELECT ('1 ' || 'month')::interval;


But this throws an error (SQL Error [42601]: ERROR: s= yntax error at or near "'1 '"):

= SELECT generate_series(
=C2=A0 =C2=A0 date_trunc('month', curre= nt_date),
=C2=A0 =C2=A0 date_trunc('month', current_date + inter= val '7 month'),
=C2=A0 =C2=A0 interval ('1 ' || 'mon= th')::interval
)


And this re= turns a series with interval of 1 second??

SELECT = generate_series(
=C2=A0 =C2=A0 date_trunc('month', current_date= ),
=C2=A0 =C2=A0 date_trunc('month', current_date + interval = 9;7 month'),
=C2=A0 =C2=A0 (interval '1 ' || 'month'= )::interval
)

Because this returns an interval = of 1 second:

SELECT (interval '1 ' || = 9;month')::interval;

Is that a bug?
=

I am able to work around the issue using a CA= SE statement, but shouldn't it work simply by concatenating the string = with the || operator?

Thank you,

Igal


--000000000000cc7991061c23275d--