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

From David Rowley
Subject Re: Should we document how column DEFAULT expressions work?
Date
Msg-id CAApHDvoiHYxM2VQYZeiF7JAdP7Y0JxEr86NZpUjoZ9AA4cpzYw@mail.gmail.com
Whole thread Raw
In response to Re: Should we document how column DEFAULT expressions work?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: Should we document how column DEFAULT expressions work?
Re: Should we document how column DEFAULT expressions work?
List pgsql-hackers
On Wed, 26 Jun 2024 at 13:31, David G. Johnston
<david.g.johnston@gmail.com> wrote:
> I'd suggest adding to:
>
> DEFAULT default_expr
> The DEFAULT clause assigns a default data value for the column whose column definition it appears within. The value
isany variable-free expression (in particular, cross-references to other columns in the current table are not allowed).
Subqueriesare not allowed either. The data type of the default expression must match the data type of the column. 
>
> The default expression will be used in any insert operation that does not specify a value for the column. If there is
nodefault for a column, then the default is null. 
>
> + Be aware that the [special timestamp values 1] are resolved immediately, not upon insert.  Use the [date/time
constructorfunctions 2] to produce a time relative to the future insertion. 

FWIW, I disagree that we need to write anything about that in this
part of the documentation.  I think any argument for doing this could
equally be applied to something like re-iterating what the operator
precedence rules for arithmetic are, and I don't think that should be
mentioned. Also, what about all the other places where someone could
use one of the special timestamp input values? Should CREATE VIEW get
a memo too?  How about PREPARE?

If people don't properly understand these special timestamp input
values, then maybe the documentation in [1] needs to be improved.  At
the moment the details are within parentheses. Namely "(In particular,
now and related strings are converted to a specific time value as soon
as they are read.)".  Maybe it would be better to be more explicit
there and mention that these are special values that the input
function understands which are translated to actual timestamp values
when the type's input function is called.  That could maybe be tied
into the DEFAULT clause documentation to mention that the input
function for constant values is called at DML time rather than DDL
time.  That way, we're not adding these (unsustainable) special cases
to the documentation.

David

[1] https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-VALUES



pgsql-hackers by date:

Previous
From: Bertrand Drouvot
Date:
Subject: Re: New standby_slot_names GUC in PG 17
Next
From: "M, Anbazhagan"
Date:
Subject: Reg: Alternate way of hashing database role passwords