Re: BUG #13812: 'now' acting differently than now() in function - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #13812: 'now' acting differently than now() in function
Date
Msg-id 22199.1449787723@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #13812: 'now' acting differently than now() in function  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thu, Dec 10, 2015 at 12:52 PM, <darin@darinhoward.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

pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #13812: 'now' acting differently than now() in function
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #13809: Reassign owned throws error