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 1sPq7N-006aKk-OI for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jul 2024 21:05:21 +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 1sPq7L-00EL8S-Ow for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jul 2024 21:05:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sPq7L-00EL8K-9y for pgsql-hackers@lists.postgresql.org; Fri, 05 Jul 2024 21:05:20 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sPq7J-000aoQ-AY for pgsql-hackers@postgresql.org; Fri, 05 Jul 2024 21:05:18 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5c25ebf6380so911788eaf.0 for ; Fri, 05 Jul 2024 14:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720213516; x=1720818316; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yR4AIw/6LFxWMuE0G8uhA3skYdGN6o6CZNg/pJjr/g8=; b=euW8kTKNWIJYK3nqYLIige6+q8L0o6iocPknUK2iWk+mFf3aHg/3CDPXVEo2LvUHP3 ACsCMZiYfTzImE4PvOrkWPuatCLwh0fu+eRGlsSBOsGzWULLsR6EpYuyLKFVb6bWRHpc 2PFM6D/cbg6Rx0iI+3tYP92TNqHIpCmS9sZD83aP3MNKxXko3XUdQlz+WJDFx1uQvDhl YVETUFI7Hc04WnPCDD+MjOmjgpCA+EbHxCtx1ak1uFVChXV2k9al/1S/J7ekdLJQ7gId XZG3c2pbsCgm1XdBOFhZuHgza0TiZpWTj9gk70JjI2YcnrLlxBlVa34lY6v7YRyfuckf cR8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720213516; x=1720818316; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yR4AIw/6LFxWMuE0G8uhA3skYdGN6o6CZNg/pJjr/g8=; b=CJF8L6/ugHoHk9zIR1lliwdbjAuLrz6cC3lkNhypd+u/ZLDHHVTg+oxNRQpPWzsAY0 SsHUZIiDzJ//N6Sd9jSIWGHNBmUyRXoMHzIq+OFO2NPW1l1Nq9EjG09lE86jXpUuU3EN g6xvQgCoiuS57RV01hqfkBhn8PV8D8Oo7TPTGoFqx9iEF0uVw7Qebo+aQVxwXkv9LzyM KYkxskf6tXANI9k0Q4r/goh/WJENICLa5o1p+AjqyG2+BW/w/Bpa2Lf6Kr3CfmnbZLca uMfBxf27S7556Aq1dEKcOOc91DsybNnDk8qPKLHbcMcGwjC/+UqxT7noFroBs9eRgKW5 wDSQ== X-Forwarded-Encrypted: i=1; AJvYcCWokU6EOOJ+ZTvtmFEW1/WLdDx1aZZXJ6jdvMQLWR0me3ovEVR10isEIqoI4mCjtrPpvyslfmBp8oDPL0ROWrHt8uxT3y2lfhVIzbZz X-Gm-Message-State: AOJu0Yzmyg+ZE5mpCpZKB7sgl0Dp4BCBjgatF6KV7uDt7+JL1uRw6LkO VoEqsdiksb0b8p91A037Quk9ufuB4p1G61fv+D9jWjx95w9vc/KjCcO7mGiLPYl8jbu1YEkgcUP UBwYqrHy3z8SXg3cLuNWk+FNeRaM= X-Google-Smtp-Source: AGHT+IGTGgfhZXkevV2/MwhibOgcicufiWAXNujD8mOEIwvFyUmKYsfdaBhWWlsT8ba7fZLj59ZCV/lNFnuNdPiHPWg= X-Received: by 2002:a4a:ab41:0:b0:5c2:1c33:b95c with SMTP id 006d021491bc7-5c649fa89e5mr2513830eaf.1.1720213516449; Fri, 05 Jul 2024 14:05:16 -0700 (PDT) MIME-Version: 1.0 References: <1642803.1719447063@sss.pgh.pa.us> <342046.1720212632@sss.pgh.pa.us> In-Reply-To: From: "David G. Johnston" Date: Fri, 5 Jul 2024 14:04:38 -0700 Message-ID: Subject: Re: Should we document how column DEFAULT expressions work? To: Bruce Momjian Cc: Tom Lane , David Rowley , Peter Eisentraut , James Coleman , pgsql-hackers Content-Type: multipart/alternative; boundary="00000000000095fd75061c866bd7" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000095fd75061c866bd7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jul 5, 2024 at 1:55=E2=80=AFPM Bruce Momjian wro= te: > On Fri, Jul 5, 2024 at 04:50:32PM -0400, Tom Lane wrote: > > Bruce Momjian writes: > > > Also interestingly, "now" without quotes requires parentheses to make > it > > > a function call: > > > > I'm not sure why you find that surprising, or why you think that > > 'now()'::timestamptz is a function call. I suspect mostly because SQL has a habit of adding functions that don't require parentheses and it isn't obvious that "now" is not one of them. select current_timestamp; current_timestamp ------------------------------- 2024-07-05 13:55:12.521334-07 (1 row) > (Well, it is a call of > > timestamptz_in, but not of the SQL function now().) Documentation > > that is equally confused won't help any. > > Well, 'now()' certainly _looks_ like a function call, though it isn't. > The fact that 'now()'::timestamptz and 'now'::timestamptz generate > volatile results via a function call was my point. > > They generate volatile results during typed value construction. That such things are implemented via functions are best left unreferenced here, reserving mention of function calls to those things users explicitly add to their query that are, and only are, function calls. Whether we change going forward or not I'd be content to simply add a warning that writing 'now()' in a default expression is invalid syntax that fails-to-fails on backward compatibility grounds. If you want the function don't quote it, if you want the literal, remove the parentheses. David J. --00000000000095fd75061c866bd7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Jul 5, 2024 at 1:55=E2=80=AFPM Bruce Momjian <<= a href=3D"mailto:bruce@momjian.us">bruce@momjian.us> wrote:
On Fri, Jul=C2=A0 5, 2024 at 04:50:32PM -0400, Tom Lane wro= te:
> Bruce Momjian <bruce@momjian.us> writes:
> > Also interestingly, "now" without quotes requires paren= theses to make it
> > a function call:
>
> I'm not sure why you find that surprising, or why you think that > 'now()'::timestamptz is a function call.

=
I suspect mostly because SQL has a habit of adding functions = that don't require parentheses and it isn't obvious that "now&= quot; is not one of them.

select current_timestamp;
= =C2=A0 =C2=A0 =C2=A0 =C2=A0current_timestamp =C2=A0 =C2=A0 =C2=A0
-----= --------------------------
=C2=A02024-07-05 13:55:12.521334-07
(1 row= )
=C2=A0
=C2=A0 (Well, it is a call of
> timestamptz_in, but not of the SQL function now().)=C2=A0 Documentatio= n
> that is equally confused won't help any.

Well, 'now()' certainly _looks_ like a function call, though it isn= 't.
The fact that 'now()'::timestamptz and 'now'::timestamptz g= enerate
volatile results via a function call was my point.


They generate volatile results during typed value constructio= n.=C2=A0 That such things are implemented via functions are best left unref= erenced here, reserving mention of function calls to those things users exp= licitly add to their query that are, and only are, function calls.
=
Whether we change going forward or not I'd be content to s= imply add a warning that writing 'now()' in a default expression is= invalid syntax that fails-to-fails on backward compatibility grounds.=C2= =A0 If you want the function don't quote it, if you want the literal, r= emove the parentheses.

David J.

--00000000000095fd75061c866bd7--