Re: Return the primary key of a newly inserted row?

Поиск
Список
Период
Сортировка
От John Tregea
Тема Re: Return the primary key of a newly inserted row?
Дата
Msg-id 449C831C.80008@debraneys.com
обсуждение исходный текст
Ответ на Re: Return the primary key of a newly inserted row?  (Scott Ribe <scott_ribe@killerbytes.com>)
Ответы Re: Return the primary key of a newly inserted row?  (Alban Hertroys <alban@magproductions.nl>)
Список pgsql-general
Scott, Ken and Tim,

Thanks for the assistance, I appreciate the advice.

Scott,

The example of

select id1 = nextval(somesequence)

could work for me. I have multiple users with our GUI and imagine I
could use transaction protection to ensure no duplicates between
selecting and incrementing the somesequence...

Thanks again all.

Regards

John


Scott Ribe wrote:
>> SQL Server had a nifty feature here.  You could simply toss a SELECT
>> statement at the end of a trigger of sproc and the results would be
>> returned.
>>
>> This in effect made a table the potential return type of all commands,
>> which could be exploited very powerfully.
>>
>> Do the hackers have any thoughts along those lines?
>>
>
> It's also a "for instance" where inline creation of variables is useful. As
> in:
>
>  select id1 = nextval(somesequence)
>  insert into tbl (id...) values (id1...)
>  select id2 = nextval(somesequence)
>  insert into tbl (id...) values (id2...)
>  select id3 = nextval(somesequence)
>  insert into tbl (id...) values (id3...)
>  select id1, id2, id3;
>
> Or returning multiple result sets...
>
>  insert into tbl (id...) values (nextval(somesequence)...) returning new.id;
>  insert into tbl (id...) values (nextval(somesequence)...) returning new.id;
>  insert into tbl (id...) values (nextval(somesequence)...) returning new.id;
>
>

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

Предыдущее
От: Greg Stark
Дата:
Сообщение: Re: Idea for vacuuming
Следующее
От: webb.sprague@gmail.com
Дата:
Сообщение: Re: Form builder?