Re: On insert duplicate row, return existing key - Mailing list pgsql-general

From Nick
Subject Re: On insert duplicate row, return existing key
Date
Msg-id 523ff3a8-79d4-403b-97c8-8ba512d1c8d8@u4g2000prn.googlegroups.com
Whole thread Raw
Responses Re: On insert duplicate row, return existing key
List pgsql-general
Anyone? Please

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.


pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Embedded text column versus referenced text
Next
From: Scott Marlowe
Date:
Subject: Re: