Re: Need special sequence generator - Mailing list pgsql-general

From A. Kretschmer
Subject Re: Need special sequence generator
Date
Msg-id 20060918105816.GC17529@a-kretschmer.de
Whole thread Raw
In response to Need special sequence generator  ("CN" <cnliou9@fastmail.fm>)
List pgsql-general
am  Mon, dem 18.09.2006, um 15:13:10 +0800 mailte CN folgendes:
> SELECT * FROM t2 WHERE a='const_id'
>
> , then 3 records will be inserted to table t1:
>
> const_id, 1
> const_id, 2
> const_id, 3
>
> I know a PL/PGSQL function like this does the job:

You can use this:

test=# select * from t2;
 id
-----
 aaa
 bbb
 aaa
 ccc
 aaa
 ddd
(6 rows)

test=*# create sequence t2_seq;
CREATE SEQUENCE
test=*# select *, nextval('t2_seq') as foo from t2 where id = 'aaa';
 id  | foo
-----+-----
 aaa |   1
 aaa |   2
 aaa |   3
(3 rows)


(You should use a temp. sequence instead...)


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47215,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

pgsql-general by date:

Previous
From: "Johannes Weberhofer, Weberhofer GmbH"
Date:
Subject: Re: Postgres 8.1.4 sanity_check failed on SuSE 8.2
Next
From: Sim Zacks
Date:
Subject: Re: transaction confusion