Re: Get id of a tuple using exception

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: Get id of a tuple using exception
Дата
Msg-id ioc14d$53p$2@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Get id of a tuple using exception  (f vf <fvalentef@gmail.com>)
Список pgsql-sql
On 2011-04-14, f vf <fvalentef@gmail.com> wrote:
> --000e0cd2bf6a60c30804a0dec84b
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hello,
> i'm using a pl/sql procedure and I prevent inserting duplicate tuples using
> an exception for example:
>
>   BEGIN
>        INSERT INTO "Triples"(id, subject, predicate, "object")
>                     VALUES (id, sub_i, pred_i, obj_i);
> * EXCEPTION WHEN unique_violation THEN
>                 --do something.
>
> *In some cases I have interest in getting the id of the tuple that was
> already in the table when the exception is triggered. Is there a way for the
> EXCEPTION to return that id instead of using a select to know wich was the
> id of the triple already existing in the table?

if the unique violation is on the ID column that's easy, if it's on
some other constraint then no there's no way to get the id.

do a select first looking for the colliding row

then fall back to an insert.

there may be weaknesses with this, it depends on why you need the Id.


-- 
⚂⚃ 100% natural



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

Предыдущее
От: Jasen Betts
Дата:
Сообщение: Re: convert in GMT time zone without summer time
Следующее
От: LaraK
Дата:
Сообщение: Re: convert in GMT time zone without summer time