Re: system maintained keys
От | Jason Earl |
---|---|
Тема | Re: system maintained keys |
Дата | |
Msg-id | 20011019185744.10807.qmail@web10002.mail.yahoo.com обсуждение исходный текст |
Ответ на | system maintained keys ("Stefan Lindner" <lindner@visionet.de>) |
Список | pgsql-sql |
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 <lindner@visionet.de> 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
В списке pgsql-sql по дате отправления: