Discussion:
SQL sentence to insert where updated rows is zero...
(too old to reply)
Glus Xof
2013-01-31 16:25:53 UTC
Permalink
Hi guys,

It's just to ask you if there is a single SQL sentence to INSERT
values in case of UPDATE WHERE returns 0 rows updated. I mean, If I
write something like,

# update my_table set column1='value' where column2='key_value';

And system replies me with one "UPDATE 0" because there is no row at
column2 with value 'key_value'... is it possible to say here: in this
case, create one new row with 'value' - 'key_value'...? like

# insert into my_table (column1, column2) values ('value', 'key_value');

Glus
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Vincent Veyron
2013-01-31 19:30:04 UTC
Permalink
Post by Glus Xof
It's just to ask you if there is a single SQL sentence to INSERT
values in case of UPDATE WHERE returns 0 rows updated. I mean, If I
write something like,
# update my_table set column1='value' where column2='key_value';
And system replies me with one "UPDATE 0" because there is no row at
column2 with value 'key_value'... is it possible to say here: in this
case, create one new row with 'value' - 'key_value'...? like
# insert into my_table (column1, column2) values ('value', 'key_value');
You might want to have a look at this page :

http://www.depesz.com/2012/06/10/why-is-upsert-so-complicated/
--
Salutations, Vincent Veyron
http://marica.fr/site/demonstration
Logiciel de gestion des contentieux juridiques et des sinistres d'assurance
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...