Re: Sequence value

Поиск
Список
Период
Сортировка
От Alessio Bragadini
Тема Re: Sequence value
Дата
Msg-id 3A3A0F6C.9A7CB21B@albourne.com
обсуждение исходный текст
Ответ на Re: Sequence value  ("Esa Pikkarainen" <epikkara@ktk.oulu.fi>)
Ответы Re: Sequence value (Record Id)  ("Esa Pikkarainen" <epikkara@ktk.oulu.fi>)
Список pgsql-general
Esa Pikkarainen wrote:

> but unfortunately it did not solve my problem. Now I have no access
> to the value of nextval('koe_pkey_id'). This query does not return
> any recordset.

Sorry, I didn't check this requirement.

> Is it possible to embed Insert query as a subquery into a Select
> query? I have not managed to dot it. I mean something like:
>
> SELECT nextval('koe_pkey_id') as val, (INSERT INTO koe (id, name)
> values (val, 'uusi')) as dummy FROM koe;"

I don't think so.

> That would both insert new record and return serial value - if it
> just worked...

In one of your examples you used a double statement, so you could
probably try:

INSERT INTO koe (id, name) (SELECT nextval('koe_pkey_id'), 'uusi');
SELECT currval('koe_pkey_id');

This should INSERT and then retrieve the same sequence value. As has
been explained to me before :-) the sequence value is safe (i.e. doesn't
get updated by another connection) inside the connection. One of your
examples was similar, but without the nextval part, so probably the
backend doesn't have a value for currval yet.

--
Alessio F. Bragadini        alessio@albourne.com
APL Financial Services        http://village.albourne.com
Nicosia, Cyprus             phone: +357-2-755750

"It is more complicated than you think"
        -- The Eighth Networking Truth from RFC 1925

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

Предыдущее
От: "Esa Pikkarainen"
Дата:
Сообщение: Re: Sequence value
Следующее
От: "Esa Pikkarainen"
Дата:
Сообщение: Re: Sequence value (Record Id)