Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oou5g-0008H2-VR for pgsql-general@arkaria.postgresql.org; Sat, 29 Oct 2022 22:14:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oou5d-0003fi-Sd for pgsql-general@arkaria.postgresql.org; Sat, 29 Oct 2022 22:14:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oou5d-0003fW-Hz for pgsql-general@lists.postgresql.org; Sat, 29 Oct 2022 22:14:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oou5V-00035B-Lp for pgsql-general@lists.postgresql.org; Sat, 29 Oct 2022 22:14:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 29TMDsAc085460; Sat, 29 Oct 2022 18:13:54 -0400 From: Tom Lane To: Adrian Klaver cc: Eagna , "pgsql-general@lists.postgresql.org" Subject: Re: How to add a variable to a timestamp. In-reply-to: <3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com> References: <3a501613-e76e-7c70-2476-e2ea4df40243@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Sat, 29 Oct 2022 13:10:24 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <85458.1667081634.1@sss.pgh.pa.us> Date: Sat, 29 Oct 2022 18:13:54 -0400 Message-ID: <85459.1667081634@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Adrian Klaver writes: > On 10/29/22 10:35, Eagna wrote: >> I'm trying to do something like this. >> '2022-10-31 00:00:00'::TIMESTAMP + INTERVAL 'd.i DAY' That will not work. A literal is a literal, you can't expect that the system will interpret parts of it as variable references. > '2022-10-31 00:00:00'::TIMESTAMP + (d.i::text || ' DAY ' || h.i::text > || ' HOUR')::interval That'll work, but my what a kluge. More recommendable is '2022-10-31 00:00:00'::TIMESTAMP + d.i * '1 day'::interval + h.i * '1 hour'::interval (Or you can spell the constants like INTERVAL '1 day', if you prefer.) regards, tom lane