pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #6047: prepare p1 as select 'now'::timestamp; then "execute p1" many times, they return the same time
3+ messages / 3 participants
[nested] [flat]
* BUG #6047: prepare p1 as select 'now'::timestamp; then "execute p1" many times, they return the same time
@ 2011-06-02 02:53 wcting163@163.com
0 siblings, 2 replies; 3+ messages in thread
From: wcting163@163.com @ 2011-06-02 02:53 UTC (permalink / raw)
To: pgsql-bugs
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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #6047: prepare p1 as select 'now'::timestamp; then "execute p1" many times, they return the same time
@ 2011-06-02 08:51 Craig Ringer <craig@postnewspapers.com.au>
parent: wcting163@163.com
1 sibling, 0 replies; 3+ messages in thread
From: Craig Ringer @ 2011-06-02 08:51 UTC (permalink / raw)
To: wcting163@163.com; +Cc: pgsql-bugs
On 02/06/11 10:53, wcting163@163.com wrote:
> but, what about "prepare p1 as select 'today'::timestamp"??
> today() is not a builtin function, we can't change it to "select
> today()::timestamp";
The keyword-to-timestamp conversions are ugly historical hacks.
Use the SQL-standard current_date, current_time, and current_timestamp
keywords instead.
http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
--
Craig Ringer
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #6047: prepare p1 as select 'now'::timestamp; then "execute p1" many times, they return the same time
@ 2011-06-02 14:10 Tom Lane <tgl@sss.pgh.pa.us>
parent: wcting163@163.com
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2011-06-02 14:10 UTC (permalink / raw)
To: wcting163@163.com; +Cc: pgsql-bugs
"" <wcting163@163.com> writes:
> 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.
Sorry, it's not a bug, and we're not going to change it.
> but, what about "prepare p1 as select 'today'::timestamp"??
> today() is not a builtin function, we can't change it to "select
> today()::timestamp";
You can get that by using date_trunc on the result of now(); or there's
current_date, which is actually SQL-standard unlike these other things.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2011-06-02 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-02 02:53 BUG #6047: prepare p1 as select 'now'::timestamp; then "execute p1" many times, they return the same time wcting163@163.com
2011-06-02 08:51 ` Craig Ringer <craig@postnewspapers.com.au>
2011-06-02 14:10 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox