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 1lovNB-0006qa-63 for pgsql-general@arkaria.postgresql.org; Thu, 03 Jun 2021 21:59:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lovN8-0002VD-FP for pgsql-general@arkaria.postgresql.org; Thu, 03 Jun 2021 21:59:26 +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 1lovN8-0002Tj-6A for pgsql-general@lists.postgresql.org; Thu, 03 Jun 2021 21:59:26 +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 1lovN6-0007y7-2x for pgsql-general@lists.postgresql.org; Thu, 03 Jun 2021 21:59:25 +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 153LxNF4102378; Thu, 3 Jun 2021 17:59:23 -0400 From: Tom Lane To: Bryn Llewellyn cc: pgsql-general list Subject: Re: =?utf-8?Q?arbitrary_=22interval=22_expression_OK_with_=22at_time_?= =?utf-8?Q?zone=22_but_not_with_=22set_time_zone=22_=E2=80=94_Why=3F?= In-reply-to: <97334D92-03D8-4066-A807-DEAC9EBF87F5@yugabyte.com> References: <97334D92-03D8-4066-A807-DEAC9EBF87F5@yugabyte.com> Comments: In-reply-to Bryn Llewellyn message dated "Thu, 03 Jun 2021 14:40:14 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <102376.1622757563.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 03 Jun 2021 17:59:23 -0400 Message-ID: <102377.1622757563@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bryn Llewellyn writes: > The "at time zone" clause that can decorate a timetsamp[tz] value seems > to allow an argument that’s an arbitrary expression that yields a value > whose data type is "interval". AT TIME ZONE is part of the SQL expression syntax, thus it's unsurprising that its arguments can be arbitrary subexpressions. > set time zone '-7 hours'::interval; > brings a "42601: syntax error". The SET statement, on the other hand, most definitely does not accept expressions of any kind; only simple literals. That's in line with most other utility commands in Postgres, but there are particularly good reasons to be wary of trying to generalize SET. Cases such as SET TRANSACTION ISOLATION LEVEL have to be able to execute without a transaction context at all. Yeah, it's asymmetric :-(. But the SQL committee has gifted us with a pretty asymmetric language, plus there are various implementation constraints that are not that easy to get rid of. regards, tom lane