pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gaetano Mendola <mendola@bigfoot.com>
To: pgsql-admin@postgresql.org
Subject: strange behaviour
Date: Sat, 27 Apr 2002 11:55:55 +0200
Message-ID: <00c301c1edd1$b9cc5b50$d5a9fea9@GMENDOLA2> (raw)

Hi to all,
I did a funciont for retrieve the actual time stamp
(not the time stamp of transaction):

CREATE FUNCTION sp_now (  ) 
RETURNS timestamp AS'
DECLARE
BEGIN
    RAISE NOTICE ''sp_now()'';
    RETURN timestamp(timeofday());
END;
' LANGUAGE 'plpgsql';


I notice that when I do some select like:

SELECT * 
FROM user_traffic 
WHERE start_date < sp_now();

the sp_now() is called for each row so I recreate
the function with the attribute iscachable:


CREATE FUNCTION sp_now (  ) 
RETURNS timestamp AS'
DECLARE

BEGIN
    RETURN timestamp(timeofday());
END;
' LANGUAGE 'plpgsql'
WITH (iscachable);

Now the select is working fine ( I mean only 
one call for all records).

I create a function like this:

CREATE FUNCTION sp_foo (  ) 
RETURNS timestamp AS'
DECLARE
    my_time_stamp    timestamp;
BEGIN
    my_time_stamp := sp_now();
  
    RETURN my_time_stamp;
END;
' LANGUAGE 'plpgsql';


and with my surprise when I do a
series of this select :     select sp_now(), sp_foo();

I obtain:

empdb=# select sp_now(), sp_foo(); 
          sp_now           |          sp_foo           
---------------------------+---------------------------
 2002-04-27 11:52:45.70+02 | 2002-04-27 11:52:45.70+02
(1 row)

empdb=# select sp_now(), sp_foo();
          sp_now           |          sp_foo           
---------------------------+---------------------------
 2002-04-27 11:52:48.07+02 | 2002-04-27 11:52:45.70+02
(1 row)

empdb=# select sp_now(), sp_foo();
          sp_now           |          sp_foo           
---------------------------+---------------------------
 2002-04-27 11:52:52.50+02 | 2002-04-27 11:52:45.70+02
(1 row)

empdb=# select sp_now(), sp_foo();
          sp_now           |          sp_foo           
---------------------------+---------------------------
 2002-04-27 11:52:54.00+02 | 2002-04-27 11:52:45.70+02

It is normal that inside sp_foo() the sp_now() is not anymore called ?


Ciao
Gaetano

-- 
#exclude <windows>
#include <CSRSS>
printf("\t\t\b\b\b\b\b\b");.
printf("\t\t\b\b\b\b\b\b");




view thread (4+ messages)  latest in thread

Message-ID: <00c301c1edd1$b9cc5b50$d5a9fea9@GMENDOLA2>
Permalink:  ../00c301c1edd1$b9cc5b50$d5a9fea9@GMENDOLA2/
Also on:    postgresql.org/message-id/00c301c1edd1$b9cc5b50$d5a9fea9@GMENDOLA2

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mendola@bigfoot.com
  Subject: Re: strange behaviour
  In-Reply-To: <00c301c1edd1$b9cc5b50$d5a9fea9@GMENDOLA2>
  References: <00c301c1edd1$b9cc5b50$d5a9fea9@GMENDOLA2>

* 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