now() in PL/pgSQL Functions

From: "Yosef Haas" <yosef(at)karatedepot(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: now() in PL/pgSQL Functions
Date: 2007-01-30 14:44:19
Message-ID: 009f01c7447d$1fb93260$0100a8c0@cqg2y51
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

This is in version 8.1.4.

I've noticed what seems to be a strange behavior - it may be by design, but
I figured I'd ask.

Run this simple test function:

create or replace function test() RETURNS bool AS '

begin

raise notice ''%'',now();

for i IN 0..50000000 loop

end loop;

raise notice ''%'',now();

return true;

end;

'

LANGUAGE 'plpgsql';

It should print the current date, wait a few seconds (by counting to 50
million)

And then print the current date. Clearly, the two dates are not identical;
however this is how it executes:

catalog=# select test();

NOTICE: 2007-01-30 09:33:19.323702-05

NOTICE: 2007-01-30 09:33:19.323702-05

test

------

t

(1 row)

For some reason it is using the same value for both "now()" calls. Is this a
bug, or by design? If it's by design what can I do to get the right time. I
know that the function only returns when it's finished executing, but
shouldn't now() return the actual time and not the time that the function
begins?

Thanks,

Yosef Haas

yosef(at)karatedepot(dot)com

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Magnus Hagander 2007-01-30 14:58:40 Re: [BUGS] Missing error message on missing ssl-key-files
Previous Message Sergiy Vyshnevetskiy 2007-01-30 13:18:36 Re: BUG #2945: possibly forgotten SPI_push()/SPI_pop()