From: | "Robby Slaughter" <webmaster(at)robbyslaughter(dot)com> |
---|---|
To: | "Virginie Garcia" <Virginie(dot)Garcia(at)pmtg(dot)u-bordeaux2(dot)fr>, <pgsql-novice(at)postgresql(dot)org> |
Subject: | RE: sequence primary key |
Date: | 2001-07-17 17:08:19 |
Message-ID: | EPEHLKLEHAHLONFOKNHNKEPDDCAA.webmaster@robbyslaughter.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Virginie,
Sounds like you could just user the SERIAL data type. Try:
CREATE TABLE toto (
toto_id SERIAL PRIMARY KEY
db TEXT);
Then whenver you do an insert...
INSERT INTO toto(db) VALUES ('and your little dog too!');
...you'll find that toto_id automagically increments for you.
Good luck. Hope this helps.
-Robby
-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org]On Behalf Of Virginie Garcia
Sent: Tuesday, July 17, 2001 10:44 AM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] sequence primary key
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(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly
From | Date | Subject | |
---|---|---|---|
Next Message | Jason Earl | 2001-07-17 18:21:19 | Re: sequence primary key |
Previous Message | Robby Slaughter | 2001-07-17 16:14:19 | RE: COUNT doesn't shows items with 0 occurrance |