From: | "A B" <gentosaker(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Problem with FOUND |
Date: | 2008-06-26 12:43:55 |
Message-ID: | dbbf25900806260543w74650595y66f4e92067ff435a@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi.
I run a function
CREATE OR REPLACE FUNCTION addRating(tbl_ INTEGER,value_ INTEGER)
RETURNS void AS $$
DECLARE
tablename TEXT;
fieldname TEXT;
BEGIN
tablename:='Rating_'||tbl_;
fieldname:='val';
EXECUTE 'UPDATE '||tablename||' SET '||fieldname||'='||value_||'
WHERE '||fieldname||'='||value_ ;
IF NOT FOUND THEN
EXECUTE 'INSERT INTO '||tablename||' ('||fieldname||') VALUES ('||value_||')';
END IF;
END;
$$ LANGUAGE plpgsql;
The UPDATE command works fine (afterwards the table is updated) but it
seems that it do the insert even if it do the update.
I thought this was a correct useage of "FOUND" so that it either do
the update or the insert, not both.
Can anyone help me spot the error?
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2008-06-26 12:50:36 | Re: 0xc3 error Text Search Windows French |
Previous Message | Michael Fuhr | 2008-06-26 12:36:08 | Re: Unicode problem again |