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 <br...@momjian.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.

-- 
  Bruce Momjian  <br...@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  When a patient asks the doctor, "Am I going to die?", he means 
  "Am I going to die soon?"
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index 83859bac76f..f5b861b387f 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -897,6 +897,13 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       does not specify a value for the column.  If there is no default
       for a column, then the default is null.
      </para>
+
+     <para>
+      Note, a string that returns a volatile result once cast to a data
+      type, like <literal>'now'::timestamptz</literal>, is evaluated at
+      table creation time, while <literal>now::timestamptz</literal>
+      (without quotes) is evaluated at data insertion time.
+     </para>
     </listitem>
    </varlistentry>
 

Reply via email to