How to get CURRENT_DATE in a pl/pgSQL function - Mailing list pgsql-sql

From Kenneth Marshall
Subject How to get CURRENT_DATE in a pl/pgSQL function
Date
Msg-id 20100518190832.GQ3892@aart.is.rice.edu
Whole thread Raw
Responses Re: How to get CURRENT_DATE in a pl/pgSQL function  (Richard Broersma <richard.broersma@gmail.com>)
List pgsql-sql
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 =
curtimeWHERE 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


pgsql-sql by date:

Previous
From: Torsten Zühlsdorff
Date:
Subject: Re: [Trigger] Help needed with NEW.* and TG_TABLE_NAME
Next
From: Richard Broersma
Date:
Subject: Re: How to get CURRENT_DATE in a pl/pgSQL function