Skip site navigation (1) Skip section navigation (2)

Re: sequence primary key

From: Jason Earl <jdearl(at)yahoo(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 18:21:19
Message-ID: 20010717182119.56217.qmail@web10001.mail.yahoo.com (view raw or flat)
Thread:
Lists: 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(dot)Garcia(at)pmtg(dot)u-bordeaux2(dot)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(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
http://personal.mail.yahoo.com/

In response to

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2001-07-17 20:42:25
Subject: Re: sequence primary key
Previous:From: Robby SlaughterDate: 2001-07-17 17:08:19
Subject: RE: sequence primary key

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group