Thread: Serial Foreign Key

Serial Foreign Key

From
Jonathan Stafford
Date:
Suppose I have two tables:

create table t1 (
   id    serial    not null
);

create table t2 (
   id    serial    not null,
   t1    integer    not null,
   foreign key (t1) references t1 (id)
);

Should the "t1 integer" actually be a bigint?  I ask because when I do
"select * from t1_id_serial" the max_value is much larger than 2^32.
Does this vary from system to system?

Thanks,
jonathan

Re: Serial Foreign Key

From
Michael Glaesemann
Date:
On Jan 7, 2005, at 14:45, Jonathan Stafford wrote:

> Suppose I have two tables:
>
> create table t1 (
>    id    serial    not null
> );
>
> create table t2 (
>    id    serial    not null,
>    t1    integer    not null,
>    foreign key (t1) references t1 (id)
> );
>
> Should the "t1 integer" actually be a bigint?  I ask because when I do
> "select * from t1_id_serial" the max_value is much larger than 2^32.
> Does this vary from system to system?

While all sequences are 64 bit integers, SERIAL is essentially INTEGER
DEFAULT nextval('foo_seq') (and creating the necessary sequence), so it
will only include 32 bit integers. If you want 64 bit integers, you can
use BIGSERIAL.

Best,

Michael Glaesemann
grzm myrealbox com