Re: sequence primary key
От | Jason Earl |
---|---|
Тема | Re: sequence primary key |
Дата | |
Msg-id | 20010717182119.56217.qmail@web10001.mail.yahoo.com обсуждение исходный текст |
Ответ на | sequence primary key (Virginie Garcia <Virginie.Garcia@pmtg.u-bordeaux2.fr>) |
Ответы |
Re: sequence primary key
|
Список | pgsql-novice |
You are *very* close to having what you want. The trick is to remember that the a "default" value is simply the value that will be inserted into your new record if you don't supply one yourself. In other words, you need to make sure that you don't specify a toto_id in your insert query. For example your query should look something like: INSERT INTO toto (db) VALUES ('SOME VALUE') And then when you select from the table you will find that the toto_id column was filled automagically. processdata=> SELECT * FROM toto; toto_id | db ---------+------------ 1 | SOME VALUE (1 row) I hope this was helpful, Jason --- Virginie Garcia <Virginie.Garcia@pmtg.u-bordeaux2.fr> wrote: > Hi all, > > my question is about sequences and primary key of a > table. > More details : I create a sequence and a table with > these lines : > > CREATE SEQUENCE "my_id" INCREMENT 1 MINVALUE 1 > MAXVALUE 2147483647 START 1 > CACHE 1; > > CREATE TABLE "toto" ( > "toto_id" integer PRIMARY KEY DEFAULT > nextval('"my_id"'), > "db" text); > > in a a sql file. > In fact, when I fill database I would like "toto_id" > field to be filled > directly by sgdb by using sequence "my_id" but not > by me. > This way doesn't work. It's perhaps a big mistake > !!! > How is-it possible, so ? > Thanks a lot. > > Virginie. > > ---------------------------(end of > broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please > send an appropriate > subscribe-nomail command to majordomo@postgresql.org > so that your > message can get through to the mailing list cleanly __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
В списке pgsql-novice по дате отправления: