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 22:00:07 |
Message-ID: | CAKFQuwZfXLcJ0aocJbNEsSMzCgn3B7qQNe4DgU=jm9+k2hGDYw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Jul 5, 2024 at 2:11 PM Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>
> 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()'.
>
>
Literals are DDL-time because of parsing, functions are insert-time because
of execution. IMO this is presently confusing because we are focused on
characters, not concepts.
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index c55fa607e8..ac661958fd 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -2391,6 +2391,17 @@ TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02'
</para>
</caution>
+ <caution>
+ <para>
+ The input parser for timestamp values is forgiving: it ignores
+ trailing invalid characters. This poses a hazard in
+ the case of the <literal>'now'</literal> special date/time input.
+ The constant <literal>'now()'</literal> is the same special
date/time input;
+ not the <function>now()</function> function, which like all function
+ call expressions, is not single-quoted. Writing
<literal>'now()'</literal>
+ is considered deprecated and may become an error in future versions.
+ </para>
+ </caution>
+
</sect3>
</sect2>
diff --git a/doc/src/sgml/ref/create_table.sgml
b/doc/src/sgml/ref/create_table.sgml
index f19306e776..4cecab011a 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -889,9 +889,10 @@ WITH ( MODULUS <replaceable
class="parameter">numeric_literal</replaceable>, REM
</para>
<para>
- The default expression will be used in any insert operation that
- does not specify a value for the column. If there is no default
- for a column, then the default is null.
+ The default expression is immediately parsed, which causes
evaluation of any literals, notably
+ <link linkend="datatype-datetime-special-table">special date/time
inputs</link>.
+ Execution happens during insert for any row that does not specify a
value for the column.
+ If there is no explicit default constraint for a column, the default
is a null value.
</para>
</listitem>
</varlistentry>
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | David Rowley | 2024-07-05 22:43:44 | Re: Should we document how column DEFAULT expressions work? |
Previous Message | Jeff Davis | 2024-07-05 21:38:45 | Re: Built-in CTYPE provider |