Skip site navigation (1) Skip section navigation (2)

Re: Primary Key with serial

From: brian <brian(at)zijn-digital(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Primary Key with serial
Date: 2008-03-29 00:41:46
Message-ID: 47ED904A.6040004@zijn-digital.com (view raw or flat)
Thread:
Lists: pgsql-general
x asasaxax wrote:
> Hi,
> 
> 
>    I have the following table    create table product(cod serial, user_cod
> bigint, constraint product_fk Foreign Key(user_cod) references user(cod),
> constraint product_pk Primary Key(cod, user_cod));
> 
> What i want to happend is that:
> user_cod            cod
> 1                         1
> 1                         2
> 1                         3
> 2                         1
> 3                         1
> 3                         2
> 
> Can serial do that?

No, a serial type will always be unique.

> If not, what can  i do to make this happen?

Re-evaluate your schema. Why do you want these two columns to have such 
a relationship? If it's very important, don't use a serial for cod and 
have your application figure out the value to assign.

b

In response to

pgsql-general by date

Next:From: Alex AdriaanseDate: 2008-03-29 00:44:08
Subject: Re: Out of memory
Previous:From: x asasaxaxDate: 2008-03-29 00:30:43
Subject: Primary Key with serial

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group