Re: INSERT or UPDATE

Поиск
Список
Период
Сортировка
От Dann Corbit
Тема Re: INSERT or UPDATE
Дата
Msg-id D425483C2C5C9F49B5B7A41F894415470296211B@postal.corporate.connx.com
обсуждение исходный текст
Ответ на Re: INSERT or UPDATE  ("James B. Byrne" <byrnejb@harte-lyne.ca>)
Ответы Re: INSERT or UPDATE  (Thomas Kellerer <spam_eater@gmx.net>)
Re: INSERT or UPDATE  ("James B. Byrne" <byrnejb@harte-lyne.ca>)
Список pgsql-general
> -----Original Message-----
> From: James B. Byrne [mailto:byrnejb@harte-lyne.ca]
> Sent: Monday, April 06, 2009 2:06 PM
> To: Dann Corbit
> Cc: pgsql-general@postgresql.org
> Subject: RE: [GENERAL] INSERT or UPDATE
>
> On Mon, April 6, 2009 17:00, Dann Corbit wrote:
> .
> >
> > It is a difficult question.
> >
> > For instance, there are many possibilities when a collision occurs.
> >
> > I guess that for some collisions, sharing the name is OK.
> >
>
> I failed to explicitly state what the PK looked like.
>
>   entity_id(entities.id) +
>   identifier_type ('AKNA') +
>   identifier_value(entities.common_name)
>
> There will only be a PK collision when we attempt to add a duplicate
> common name for the same entity, which means it already exists and
> does not need to be added again.

The pedagogic solution for this type of problem is called merge.
The last I knew, PostgreSQL did not directly support merge.
So you can accomplish the same thing in two stages:
1. Check for existence and perform an update if the key is present
2. If the key is not present, then perform an insert.

Again, this may or may not be the right thing to do.

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

Предыдущее
От: feridun türk
Дата:
Сообщение: E-mail List -- Feridun Türk
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: INSERT or UPDATE