X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4BF96329E3D for ; Tue, 5 Oct 2004 16:38:07 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49219-09 for ; Tue, 5 Oct 2004 15:37:57 +0000 (GMT) Received: from mail.informatik.hu-berlin.de (mail.informatik.hu-berlin.de [141.20.20.50]) by svr1.postgresql.org (Postfix) with ESMTP id 509D9329CD9 for ; Tue, 5 Oct 2004 16:37:56 +0100 (BST) Received: from informatik.hu-berlin.de (karotte [141.20.27.143]) (authenticated bits=0) by mail.informatik.hu-berlin.de (8.12.10/8.12.10/INF-2.0-MA-SOLARIS-2.8) with ESMTP id i95Fbpgt025617 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 5 Oct 2004 17:37:52 +0200 (MEST) Message-ID: <4162BFCF.9090501@informatik.hu-berlin.de> Date: Tue, 05 Oct 2004 17:37:51 +0200 From: Silke Trissl User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.4) Gecko/20030624 X-Accept-Language: de-at, de, en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Using timestamp in function Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/29 X-Sequence-Number: 19132 Hi, I am using PostgreSQL 7.4 and was trying to log the time each part of a function needs. I found a pretty helpful bit of code in the documentation: http://www.postgresql.org/docs/7.4/static/plpgsql-expressions.html I used the following function, called inside the another function: 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. Can anyone tell me why this does not work and does anyone know a solution to this? For test purposes here is a function called test, which does nothing else than to call mylog_test(..) and spend some time calculating. CREATE or replace FUNCTION test() RETURNS text AS ' DECLARE i integer; j integer; k integer; BEGIN FOR i IN 1..10 LOOP PERFORM mylog(3, ''val '' || i); FOR j IN 1..2000000 LOOP k:=j; END LOOP; END LOOP; RETURN ''THE END''; END; ' LANGUAGE 'plpgsql'; SELECT test(); Any help is appreciated Silke