Subject: Re: Should we document how column DEFAULT expressions work?

From: "David G. Johnston" <[email-masked]>
Date: Fri, 5 Jul 2024 14:04:38 -0700

On Fri, Jul 5, 2024 at 1:55 PM Bruce Momjian <[email-masked]> wrote:

> On Fri, Jul  5, 2024 at 04:50:32PM -0400, Tom Lane wrote:
> > Bruce Momjian <[email-masked]> 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.