Re: BUG #13812: 'now' acting differently than now() in function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: darin(at)darinhoward(dot)com, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13812: 'now' acting differently than now() in function
Date: 2015-12-10 22:48:43
Message-ID: 22199.1449787723@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thu, Dec 10, 2015 at 12:52 PM, <darin(at)darinhoward(dot)com> wrote:
>> I would not expect the date2 on row 2 to be the same date2 as row 1.

> I may be missing a nuance here, this could
> maybe use better documentation surrounding implications, but the basic
> answer is that 'now' is a string literal that ends up getting resolved at
> parse time during the first invocation of the function and then its value
> is cached and re-used during subsequent executions. The "now()" volatile
> function is instead left alone by the parser and instead is invoked during
> each execution of the UPDATE.

> I am going from memory here since I cannot locate the documentation that
> points out this fact...

There's some discussion near the bottom of this page:
http://www.postgresql.org/docs/9.4/static/plpgsql-implementation.html

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jhonatan Martinez 2015-12-11 20:05:34 Error postgres9.5
Previous Message David G. Johnston 2015-12-10 21:18:55 Re: BUG #13812: 'now' acting differently than now() in function