Re: On insert duplicate row, return existing key
Started by Nickover 15 years ago2 messagesgeneral
Anyone? Please
Show quoted text
On Jul 31, 12:36 pm, Nick <nboutel...@gmail.com> wrote:
If I insert a duplicate row into a table, id like to return the
existing key.I tried creating a rule for this...
CREATE RULE no_duplicates AS ON INSERT TO names WHERE EXISTS (SELECT 1
FROM names WHERE new.name = name) DO INSTEAD SELECT id, name FROM
names WHERE name = new.name;However, I get an error on...
INSERT INTO names (name) VALUES ('existing') RETURNING *;
ERROR: cannot perform INSERT RETURNING on relation "names"
HINT: You need an unconditional ON INSERT DO INSTEAD rule with a
RETURNING clause.
Import Notes
Reference msg id not found: a572df3a-50bf-46d9-b312-6c5d32378597@n19g2000prf.googlegroups.com