Received: from web10002.mail.yahoo.com (web10002.mail.yahoo.com [216.136.130.38]) by postgresql.org (8.11.3/8.11.4) with SMTP id f9JIvkP26020 for ; Fri, 19 Oct 2001 14:57:46 -0400 (EDT) (envelope-from jdearl@yahoo.com) Message-ID: <20011019185744.10807.qmail@web10002.mail.yahoo.com> Received: from [12.18.144.101] by web10002.mail.yahoo.com via HTTP; Fri, 19 Oct 2001 11:57:44 PDT Date: Fri, 19 Oct 2001 11:57:44 -0700 (PDT) From: Jason Earl Subject: Re: system maintained keys To: Stefan Lindner , pgsql-sql@postgresql.org In-Reply-To: <9qf06v$20bh$1@news.tht.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200110/283 X-Sequence-Number: 5236 Check out the SERIAL type. It does precisely what you want. An idea as to how this is used would be like this: CREATE TABLE foo ( prim_key SERIAL PRIMARY KEY, bar text ); I tend to create sequences by hand like this: CREATE SEQUENCE my_sequence_seq; And then I create my table with a definition like this: CREATE TABLE foo ( prim_key int DEFAULT nextval('my_sequence_seq') PRIMARY KEY, bar text, ); But that's just because I have been using PostgreSQL long enough that it didn't have the SERIAL type when I started. The SERIAL type is just syntactic sugar for what I generally do the long way. Either way you simply pretend that the column isn't there when you do inserts (unless you know what you are doing) like so: INSERT INTO foo (bar) VALUES ('hello'); INSERT INTO foo (bar) VALUES ('goodbye'); And then when you select you get: processdata=> SELECT * FROM foo; prim_key | bar ----------+--------- 1 | hello 2 | goodbye (2 rows) I hope that is helpful, Jason Earl --- Stefan Lindner wrote: > Is there any way to get system maintained keys from > postgres? e.g. to > have a table with a primary key column (varchar or > int) and let postgres > chose the next unique value for this column? > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com