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: Should we document how column DEFAULT expressions work?
Date: 2024-10-16 23:45:39
Message-ID: CAKFQuwZ89s_3ytHw58_o=BFxhpdTwR4UbyDXmOSa05fUFfmFew@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wednesday, October 16, 2024, Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> On Fri, Jul 5, 2024 at 05:11:22PM -0400, Bruce Momjian wrote:
> > On Fri, Jul 5, 2024 at 05:03:35PM -0400, Tom Lane wrote:
> > > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > > 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.
> > >
> > > The only reason 'now()'::timestamptz works is that timestamptz_in
> > > ignores irrelevant punctuation (or what it thinks is irrelevant,
> > > anyway). I do not think we should include examples that look like
> > > that, because it will further confuse readers who don't already
> > > have a solid grasp of how this works.
> >
> > Wow, I see that now:
> >
> > test=> SELECT 'now('::timestamptz;
> > timestamptz
> > -------------------------------
> > 2024-07-05 17:04:33.457915-04
> >
> > If I remove the 'now()' mention in the docs, patch attached, I am
> > concerned people will be confused whether it is the removal of the
> > single quotes or the use of "()" which causes insert-time evaluation,
> > and they might try 'now()'.
>
> Does anyone like this patch? I changed now()::timestamptz to
> now::timestamptz.
>

I do not, but maybe I’m being overly pedantic. All string literals are
parsed during the create table command. It’s only the situations where
that parsing is non-deterministic that cause an issue.

Is there anything wrong with the patch I proposed?

David J.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-10-16 23:50:27 Re: [BUG FIX] Fix validation of COPY options FORCE_NOT_NULL/FORCE_NULL
Previous Message Matthias van de Meent 2024-10-16 23:32:44 Re: Limiting overshoot in nbtree's parallel SAOP index scans