Re: Should we document how column DEFAULT expressions work?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Rowley <dgrowleyml(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, James Coleman <jtc331(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Should we document how column DEFAULT expressions work?
Date: 2024-07-05 21:04:38
Message-ID: CAKFQuwZ883st30LHSh1O0=uSzhCEntMKW1n1VXYaRtWqvvwEMw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 5, 2024 at 1:55 PM Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> On Fri, Jul 5, 2024 at 04:50:32PM -0400, Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2024-07-05 21:11:22 Re: Should we document how column DEFAULT expressions work?
Previous Message Tom Lane 2024-07-05 21:03:35 Re: Should we document how column DEFAULT expressions work?