Re: Sequence value

From: Alessio Bragadini <alessio(at)albourne(dot)com>
To: epikkara(at)ktk(dot)oulu(dot)fi
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Sequence value
Date: 2000-12-15 12:32:44
Message-ID: 3A3A0F6C.9A7CB21B@albourne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)albourne(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Esa Pikkarainen 2000-12-15 13:09:00 Re: Sequence value (Record Id)
Previous Message Esa Pikkarainen 2000-12-15 12:14:45 Re: Sequence value