Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D5E9FB60934 for ; Wed, 1 Jun 2011 23:53:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 81149-09 for ; Thu, 2 Jun 2011 02:53:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 2D50BB60909 for ; Wed, 1 Jun 2011 23:53:02 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p522r1rt076377 for ; Thu, 2 Jun 2011 02:53:01 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p522r1eD076376; Thu, 2 Jun 2011 02:53:01 GMT (envelope-from www) Date: Thu, 2 Jun 2011 02:53:01 GMT Message-Id: <201106020253.p522r1eD076376@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6047: prepare p1 as select 'now'::timestamp; then "execute p1" many times, they return the same time From: "" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201106/12 X-Sequence-Number: 30391 The following bug has been logged online: Bug reference: 6047 Logged by: Email address: wcting163@163.com PostgreSQL version: 9.0.4 Operating system: WinXP 32bit Description: prepare p1 as select 'now'::timestamp; then "execute p1" many times, they return the same time Details: when i execute the following statements: prepare p1 as select 'now'::timestamp; execute p1; execute p1; every time i execute statement "execute p1", they all return the same time, the time when "prepare p1 ..." is created. but i expect it return the changing time ---- the current time. 1). although i kown that, "the system will convert **now** to a timestamp as soon as the constant is parsed", i think this is a bug. 2). maybe you suggest me: prepare p1 as select now()::timestamp; then "execute p1" will return the current time. this is because now() is a builtin function, so we can change "select 'now'::timestamp" to "select now()::timestamp"; but, what about "prepare p1 as select 'today'::timestamp"?? today() is not a builtin function, we can't change it to "select today()::timestamp"; So, the implementation method of "now" and "today" is different, and prepare p1 as select 'today'::timestamp; execute p1;-- will always return the day when the "prepare p1 ..." is created, even we're in another day.