Search Postgresql Archives

Re: On insert duplicate row, return existing key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Anyone? Please

On Jul 31, 12:36 pm, Nick <nboutel...@xxxxxxxxx> 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.


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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux