serial nextval() question - Mailing list pgsql-general

From Jean-Christian Imbeault
Subject serial nextval() question
Date
Msg-id 3D5CC1D1.80907@mega-bucks.co.jp
Whole thread Raw
Responses Re: serial nextval() question
List pgsql-general
I have the following table def:

create table TMP_LI (

cart_id                 integer         references TMP_CART(id),
li_id                   integer         not null,
shop_id                 integer         references CHARISMA_SHOPS(id),
prod_id                 char(12)        references PRODUCTS(id),
quantity                int2            not null,
price                   integer         not null,

primary key (cart_id, li_id)
);

I'd like to have li_id be an serial but not for the whole table, only as
li_id relates to cart_id ... i.e. I'd like li_id to increment relative
to cart_id so that I can generate sequences of the kind:

cart_id      li_id
1         1
1         2
1         3
2         1
2
    2

How could I do this?

Thanks!

Jc


pgsql-general by date:

Previous
From: mixo
Date:
Subject: last entry
Next
From: Manfred Koizar
Date:
Subject: Re: performance with triggers depends on table size?