Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) by postgresql.org (Postfix) with ESMTP id AA2D34758FE for ; Sat, 27 Apr 2002 05:56:01 -0400 (EDT) Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id g3R9tsR24162 for ; Sat, 27 Apr 2002 11:55:54 +0200 Received: from dell-01.mm.eutelsat.org (IDENT:root@dell-01.mm.eutelsat.org [194.214.173.17]) by nts-03.mm.eutelsat.org (8.9.3/8.8.7) with ESMTP id LAA14384 for ; Sat, 27 Apr 2002 11:53:55 +0200 Received: from GMENDOLA2 (gmendola2.mm.eutelsat.org [194.214.173.26]) by dell-01.mm.eutelsat.org (8.11.2/8.8.7) with SMTP id g3R9tsR25656 for ; Sat, 27 Apr 2002 11:55:54 +0200 Message-ID: <00c301c1edd1$b9cc5b50$d5a9fea9@GMENDOLA2> From: "Gaetano Mendola" To: Subject: strange behaviour Date: Sat, 27 Apr 2002 11:55:55 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200204/272 X-Sequence-Number: 4160 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 #include printf("\t\t\b\b\b\b\b\b");. printf("\t\t\b\b\b\b\b\b");