diff options
-rw-r--r-- | doc/src/sgml/datatype.sgml | 20 | ||||
-rw-r--r-- | doc/src/sgml/func.sgml | 8 |
2 files changed, 22 insertions, 6 deletions
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 0d38bee1820..44d85d81afe 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -2103,7 +2103,7 @@ January 8 04:05:06 1999 PST </para> </sect3> - <sect3> + <sect3 id="datatype-datetime-special-values"> <title>Special Values</title> <indexterm> @@ -2191,12 +2191,26 @@ January 8 04:05:06 1999 PST type: <literal>CURRENT_DATE</literal>, <literal>CURRENT_TIME</literal>, <literal>CURRENT_TIMESTAMP</literal>, <literal>LOCALTIME</literal>, - <literal>LOCALTIMESTAMP</literal>. The latter four accept an - optional subsecond precision specification. (See <xref + <literal>LOCALTIMESTAMP</literal>. (See <xref linkend="functions-datetime-current"/>.) Note that these are SQL functions and are <emphasis>not</emphasis> recognized in data input strings. </para> + <caution> + <para> + While the input strings <literal>now</literal>, + <literal>today</literal>, <literal>tomorrow</literal>, + and <literal>yesterday</literal> are fine to use in interactive SQL + commands, they can have surprising behavior when the command is + saved to be executed later, for example in prepared statements, + views, and function definitions. The string can be converted to a + specific time value that continues to be used long after it becomes + stale. Use one of the SQL functions instead in such contexts. + For example, <literal>CURRENT_DATE + 1</literal> is safer than + <literal>'tomorrow'::date</literal>. + </para> + </caution> + </sect3> </sect2> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 4313dc5a1e5..0028e53ef1e 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -8340,20 +8340,22 @@ now() <programlisting> SELECT CURRENT_TIMESTAMP; SELECT now(); -SELECT TIMESTAMP 'now'; -- incorrect for use with DEFAULT +SELECT TIMESTAMP 'now'; -- but see tip below </programlisting> </para> <tip> <para> - You do not want to use the third form when specifying a <literal>DEFAULT</literal> - clause while creating a table. The system will convert <literal>now</literal> + Do not use the third form when specifying a value to be evaluated later, + for example in a <literal>DEFAULT</literal> clause for a table column. + The system will convert <literal>now</literal> to a <type>timestamp</type> as soon as the constant is parsed, so that when the default value is needed, the time of the table creation would be used! The first two forms will not be evaluated until the default value is used, because they are function calls. Thus they will give the desired behavior of defaulting to the time of row insertion. + (See also <xref linkend="datatype-datetime-special-values"/>.) </para> </tip> </sect2> |