Re: Foreign Key: what value? - Mailing list pgsql-sql

From Aaron Bono
Subject Re: Foreign Key: what value?
Date
Msg-id bf05e51c0607061232k54a9578dhdcc8fa6795d952b7@mail.gmail.com
Whole thread Raw
In response to Re: Foreign Key: what value?  (<operationsengineer1@yahoo.com>)
List pgsql-sql
On 7/6/06, operationsengineer1@yahoo.com <operationsengineer1@yahoo.com> wrote:
i alsways make my foreign key column data type int4.
i'm not sure if i read that somewhere.  anyone, please
feel free to chime in if this isn't good practice.

read up on currval, nextval and that whole section.
you can begin by getting the nextval, assigning it to
a variable, insert it into your primary table and then
insert it into your related table as a foreign key.

from what i understand, either way should be
bulletproof.  the way i described is more code, but
some minds might not mind paying that price b/c they
like the process better.

good luck.

Bigserial's are simply bigint's with a sequence that does the nextval part for you.  Your approach works but takes more coding on your part.  I would recommend using bigserial so you cut some of the work out for yourself.

-Aaron

pgsql-sql by date:

Previous
From:
Date:
Subject: Re: Foreign Key: what value?
Next
From: "David Clarke"
Date:
Subject: Re: Alternative to serial primary key