Re: How to insert record only if primary key does not exist

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: How to insert record only if primary key does not exist
Дата
Msg-id 4FF05C5C.2070204@ringerc.id.au
обсуждение исходный текст
Ответ на How to insert record only if primary key does not exist  ("Andrus" <kobruleht2@hot.ee>)
Ответы Re: How to insert record only if primary key does not exist  (Chris Angelico <rosuav@gmail.com>)
Список pgsql-general
On 06/30/2012 09:02 PM, Andrus wrote:
Table is defined as
 
CREATE TABLE firma1.klient (
  kood character(12) NOT NULL DEFAULT nextval('firma1.klient_kood_seq'::regclass),
....
);
 
How to insert record to this table only if primary key does not exist ?

You want an operation that's called an UPSERT or MERGE operation. PostgreSQL doesn't have any native support to do this for you. Doing it right is surprisingly tricky. This is the best article I've seen on the topic:

http://www.depesz.com/2012/06/10/why-is-upsert-so-complicated/

--
Craig Ringer

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

Предыдущее
От: AI Rumman
Дата:
Сообщение: is there any query so that I may find the list of columns those have rules?
Следующее
От: Chris Angelico
Дата:
Сообщение: Re: How to insert record only if primary key does not exist