serial nextval() question

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: serial nextval() question
Date: 2002-08-16 09:11:45
Message-ID: 3D5CC1D1.80907@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Manfred Koizar 2002-08-16 09:19:18 Re: performance with triggers depends on table size?
Previous Message Ben-Nes Michael 2002-08-16 08:44:13 pg_query & pg_last_oid