What is the postgres version of mysql's "ON DUPLICATE KEY"

Поиск
Список
Период
Сортировка
От nboutelier@hotmail.com (Nick)
Тема What is the postgres version of mysql's "ON DUPLICATE KEY"
Дата
Msg-id ce0d844c.0409101033.611f8b44@posting.google.com
обсуждение исходный текст
Список pgsql-general
I have a table with columns
(product_id,related_product_id,related_counter)

If product A is related to product B then a record should be created,
if the record already exists then the related_counter should be
incremented.

This is very easy to do with MySQL using INSERT... ON DUPLICATE KEY.
Standard or not, it is very usefull.

Is there a way to catch the insert error. For example...

INSERT INTO related_products (product_id,related_product_id) VALUES
(?,?);
IF (???error: duplicate key???) THEN
UPDATE related_products SET related_counter = related_counter + 1;
END IF;

-Nick

В списке pgsql-general по дате отправления:

Предыдущее
От: Michael Wimmer
Дата:
Сообщение: unicode and varchar
Следующее
От: Gaetano Mendola
Дата:
Сообщение: Re: Salt in encrypted password in pg_shadow