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
I hope this was helpful,
--- Virginie Garcia
> Hi all,
> my question is about sequences and primary key of a
> 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
> "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.
> ---------------------------(end of
> 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
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
In response to
pgsql-novice by date
|Next:||From: Tom Lane||Date: 2001-07-17 20:42:25|
|Subject: Re: sequence primary key |
|Previous:||From: Robby Slaughter||Date: 2001-07-17 17:08:19|
|Subject: RE: sequence primary key |