From: | Alex Pilosov <alex(at)pilosoft(dot)com> |
---|---|
To: | Tomas Eriksson <tomas(at)embryo(dot)se> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Variables in Postgresql |
Date: | 2001-06-11 13:31:28 |
Message-ID: | Pine.BSO.4.10.10106110929520.17529-100000@spider.pilosoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Assuming you have table foo with a sequence foo_seq, you can do this:
insert into foo (fields) values (....)
insert into bar (fields) select foo_seq.currval, ....
In other words, foo_seq.currval will always return the last value used by
your transaction.
-alex
On Mon, 4 Jun 2001, Tomas Eriksson wrote:
> Hi.
>
> I haven't seen any documentation about this, how do you use variables in a
> simple way in postgresql? I want to use same sequence number in a dynamic
> query from Perl.
>
> When i'm using MSSQL i can do like this in a single query
>
> "DECLARE @owner INT
> INSERT maintable (fields) VALUES (...)
> SELECT @owner = @@IDENTITY
> INSERT subtable (fields) VALUES (@owner, ...)"
>
> How does I save a value and using it later in the query..?
>
> kind regards
> Tomas
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Shaun Thomas | 2001-06-11 13:43:39 | Re: foreign keys constraints, depending on each other |
Previous Message | Pasi Salminen | 2001-06-11 13:02:40 | Include file problem |