Thread: which type for primary key?

which type for primary key?

From
Rafal Kedziorski
Date:
Hi,

I'm working on J2EE project with PostgreSQL (7.3.2). I know, that a 
number type is better for primary key as string. I want create primary 
keys as NUMBER(20). Is this a good idea? what will be a performance for 
this length?


Best Regards,
Rafal



Re: which type for primary key?

From
Tomasz Myrta
Date:
Rafal Kedziorski wrote:
> Hi,
> 
> I'm working on J2EE project with PostgreSQL (7.3.2). I know, that a 
> number type is better for primary key as string. I want create primary 
> keys as NUMBER(20). Is this a good idea? what will be a performance for 
> this length?

Postgresql documentation 5.1.2:
"However, the numeric type is very slow compared to the floating-point types described in the next section"
I'm not sure, but number(20) is 10 or 20 bytes length (you need to check this),
which is rather long variable for primary key.

I use always int4 or int8 for primary keys when possible.

Regards,
Tomasz Myrta