Received: from maia.hub.org (maia-4.hub.org [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8705E632C14 for ; Tue, 18 May 2010 16:08:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 65609-03 for ; Tue, 18 May 2010 19:08:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh5.mail.rice.edu (mh5.mail.rice.edu [128.42.199.32]) by mail.postgresql.org (Postfix) with ESMTP id 282706325C8 for ; Tue, 18 May 2010 16:08:35 -0300 (ADT) Received: from mh5.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh5.mail.rice.edu (Postfix) with ESMTP id BC38B15C059 for ; Tue, 18 May 2010 14:08:33 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.0 at mh5.mail.rice.edu Received: from mh5.mail.rice.edu ([127.0.0.1]) by mh5.mail.rice.edu (mh5.mail.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2eqDacLvs+U6 for ; Tue, 18 May 2010 14:08:33 -0500 (CDT) Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh5.mail.rice.edu (Postfix) with ESMTP id 9BDB215C047 for ; Tue, 18 May 2010 14:08:33 -0500 (CDT) Received: by aart.is.rice.edu (Postfix, from userid 18612) id EFC6A2D5A6; Tue, 18 May 2010 14:08:32 -0500 (CDT) Date: Tue, 18 May 2010 14:08:32 -0500 From: Kenneth Marshall To: pgsql-sql@postgresql.org Subject: How to get CURRENT_DATE in a pl/pgSQL function Message-ID: <20100518190832.GQ3892@aart.is.rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/76 X-Sequence-Number: 34124 I am trying to write a function that updates the date column to the current date. According to: http://www.postgresql.org/docs/8.4/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT you can use CURRENT_DATE. When I try to use it in the following pl/pgSQL function it gives the error: ERROR: date/time value "current" is no longer supported CONTEXT: PL/pgSQL function "merge_data" line 4 at assignment Here is the code I am using: CREATE FUNCTION merge_data(key INT, i INT) RETURNS VOID AS $$ DECLARE curtime date; BEGIN curtime := 'CURRENT_DATE'; LOOP -- first try to update the key UPDATE data SET count = i, date = curtime WHERE k = key; IF found THEN RETURN; END IF; -- not there, so try to insert the key -- if someone else inserts the same key concurrently, -- we could get a unique-key failure BEGIN INSERT INTO data(k, count, date) VALUES (key, i, curtime); RETURN; EXCEPTION WHEN unique_violation THEN -- do nothing, and loop to try the UPDATE again END; END LOOP; END; $$ LANGUAGE plpgsql; It looks like it is keying on the CURRENT and dropping the _DATE piece. I suspect that I am doing something wrong but I am not able to find a pointer in the docs or mailing lists. Any help would be greatly appreciated. Regards, Ken