Re: Is there any different for foreign key to be serial instead of integer - Mailing list pgsql-general

From Scott Marlowe
Subject Re: Is there any different for foreign key to be serial instead of integer
Date
Msg-id dcc563d11001062036m7d3bdcf8w51813a2bd7e0d5a1@mail.gmail.com
Whole thread Raw
In response to Re: Is there any different for foreign key to be serial instead of integer  (Richard Broersma <richard.broersma@gmail.com>)
Responses Re: Is there any different for foreign key to be serial instead of integer  (Richard Broersma <richard.broersma@gmail.com>)
List pgsql-general
On Wed, Jan 6, 2010 at 9:08 PM, Richard Broersma
<richard.broersma@gmail.com> wrote:
> On Wed, Jan 6, 2010 at 7:51 PM, Yan Cheng Cheok <yccheok@yahoo.com> wrote:
>
>
>> instead of let customer_id being type as integer, can i let it be serial? is there any difference?
>>
>> if the table referenced by customer_id is having primary key typed big serial, customer_id shall be declared as
bigint? 
>
> This is a good section about the distinction between:
>
> serial -> integer
> bigserial -> bigint
>
> the short answer is that the serial type is actually is the datatype
> *integer* with the sequence generator attached to the default value of
> the column.
>
> So it only makes sense for primary key to be defined as serial.  A
> serial foreign key would be nonsensical since foreign keys should be
> be generating their own values.

Pretty sure the OP was talking about referencing a bigserial from a
foreign key, which makes perfect sense for certain types of mappings.
FKs don't generate their own values, they reference values in a PK or
unique field somewhere else really.

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: How to call SETOF function?
Next
From: Richard Broersma
Date:
Subject: Re: Is there any different for foreign key to be serial instead of integer