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

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to