From: Michael Fuhr <mike@fuhr.org>
To: Silke Trissl <trissl@informatik.hu-berlin.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: Using timestamp in function
Date: Tue, 5 Oct 2004 10:19:12 -0600
Message-ID: <20041005161912.GA55627@winnie.fuhr.org> (raw)
In-Reply-To: <4162BFCF.9090501@informatik.hu-berlin.de>
References: <4162BFCF.9090501@informatik.hu-berlin.de>
On Tue, Oct 05, 2004 at 05:37:51PM +0200, Silke Trissl wrote:
> CREATE or replace FUNCTION mylog_test(integer, varchar) RETURNS
> timestamp AS '
> DECLARE
> n ALIAS FOR $1;
> logtxt ALIAS FOR $2;
> curtime timestamp;
> BEGIN
> curtime := ''now'';
> --INSERT INTO logger VALUES ( nextval(''seq_log''), curtime,
> substr(logtxt,0,200));
> RAISE NOTICE ''TIME: %'',curtime;
> RETURN curtime;
> END;
> ' LANGUAGE plpgsql;
>
> I expected, that the variable curtime gets a new time value, each time
> the function is called (at least that is what I understood from the
> documentation). This works fine, if I test it with
> SELECT mylog_test(5, 'test');
> But as soon as I call the funtion from another function (which I need)
> the variable curtime does not change anymore.
"Functions and trigger procedures are always executed within a
transaction established by an outer query...." [1]
"It is important to know that CURRENT_TIMESTAMP and related functions
return the start time of the current transaction; their values do not
change during the transaction....timeofday() returns the wall-clock
time and does advance during transactions." [2]
[1] http://www.postgresql.org/docs/7.4/static/plpgsql-structure.html
[2] http://www.postgresql.org/docs/7.4/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@fuhr.org, trissl@informatik.hu-berlin.de
Subject: Re: Using timestamp in function
In-Reply-To: <20041005161912.GA55627@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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