Re: Should we document how column DEFAULT expressions work? - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Should we document how column DEFAULT expressions work?
Date
Msg-id CAKFQuwZ883st30LHSh1O0=uSzhCEntMKW1n1VXYaRtWqvvwEMw@mail.gmail.com
Whole thread Raw
In response to Re: Should we document how column DEFAULT expressions work?  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
On Fri, Jul 5, 2024 at 1:55 PM Bruce Momjian <bruce@momjian.us> wrote:
On Fri, Jul  5, 2024 at 04:50:32PM -0400, Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> 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.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Should we document how column DEFAULT expressions work?
Next
From: Bruce Momjian
Date:
Subject: Re: Should we document how column DEFAULT expressions work?