X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 684D09F94F3 for ; Thu, 6 Jul 2006 16:32:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 01454-10 for ; Thu, 6 Jul 2006 16:32:48 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.191]) by postgresql.org (Postfix) with ESMTP id 446839FA0EC for ; Thu, 6 Jul 2006 16:32:47 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id x4so26053nfb for ; Thu, 06 Jul 2006 12:32:46 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=pjYVrSj83rqzGE7dPkJLIci5kgiEn3lVn8fE86Vpqv9jd6JQPfp7Wd7A2FgwWcCMlG88qdQxIdjZmEkPz3do7PyDKiCCTPGUQVfP1q8p9sq/8jcPTPkJSTffQmKL7DLanM8jO3i5hvTxjTCvaVd6rLKUSviuMhMkdC+tPmgSLFY= Received: by 10.78.165.16 with SMTP id n16mr332500hue; Thu, 06 Jul 2006 12:32:46 -0700 (PDT) Received: by 10.78.29.2 with HTTP; Thu, 6 Jul 2006 12:32:45 -0700 (PDT) Message-ID: Date: Thu, 6 Jul 2006 14:32:45 -0500 From: "Aaron Bono" To: "operationsengineer1@yahoo.com" Subject: Re: Foreign Key: what value? Cc: "Davi Leal" , pgsql-sql@postgresql.org In-Reply-To: <20060706184634.50283.qmail@web33314.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_98761_15781269.1152214365843" References: <200607051719.27466.davi@leals.com> <20060706184634.50283.qmail@web33314.mail.mud.yahoo.com> X-Google-Sender-Auth: 3c8462776e228533 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/69 X-Sequence-Number: 25643 ------=_Part_98761_15781269.1152214365843 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/6/06, 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 ------=_Part_98761_15781269.1152214365843 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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

------=_Part_98761_15781269.1152214365843--