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

Re: Data type for serial during constraint?

From: Ed Loehr <eloehr(at)austin(dot)rr(dot)com>
To: rslifka(at)home(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Data type for serial during constraint?
Date: 2000-05-31 02:22:17
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
> "Rob S." wrote:
> >
> > Question tho':  I've specified a SERIAL primary key ("fooID") in some table
> > ("t1").  From another table, I'd like to specify that primary key as a
> > foreign key.  I have to include a data type, but that will create another
> > sequencer for that field, which I would imagine is not the way root
> > intended?  for "t2"...
> >
> > CREATE TABLE "T2" ( "t2ID" SERIAL, "fooID" ???? REFERENCES "t1" ("fooID") );
> >
> > What goes where the '?' are?  Thanks in advance!

SERIAL is not really a first-class type.  Here's an example that reveals
the parser translation into an integer type:

testdb=# create table foo (id serial primary key);
NOTICE:  CREATE TABLE will create implicit sequence 'foo_id_seq' for
SERIAL column ''
NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index 'foo_pkey'
for table 'foo'
testdb=# \d foo
                            Table "foo"
 Attribute |  Type   |                   Modifier                   
 id        | integer | not null default nextval('foo_id_seq'::text)
Index: foo_pkey

Ed Loehr

In response to

pgsql-general by date

Next:From: Tom LaneDate: 2000-05-31 06:17:55
Subject: Re: Perl interfaces?
Previous:From: Vince VielhaberDate: 2000-05-31 02:10:16
Subject: Re: Postgresql usage clip.

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