Chield Serial

From: lucas(at)presserv(dot)org
To: pgsql-sql(at)postgresql(dot)org
Subject: Chield Serial
Date: 2005-04-04 13:01:02
Message-ID: 20050404100102.z7ohducpsei8s0c8@www.presserv.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi.
Is there a way to make a serial columm that works with father table???
I.e:
I have created a table called "vending" and its chield table called "items".
The items table have a serial columm, but I need the serial colum starts with 0
for each vending.

create table vending (
id serial primary key, --Ok, this serial: 0 - 9999xxx
date_ date
);
create table items (
vending_id references vending,
items_id serial, -- THIS SERIAL NEED to start 0 for each vending_id
primary key (vending_id,items_id)
);
insert into vending values (1,now());
insert into vending values (2,now());
insert into items values (1);
insert into items values (1);
insert into items values (2);
insert into items values (2);
select * from items;

vending_id | items_id
1 | 1
1 | 2
2 | 3 <<=== Here! The items_id need to be 1 (start again
for each vending_id)
2 | 4 <<==
Thanks all.

Browse pgsql-sql by date

  From Date Subject
Next Message Dinesh Pandey 2005-04-04 13:41:17 Migrated Oracle database to PostgreSQL ??
Previous Message Michael L. Hostbaek 2005-04-04 12:23:34 Re: select & group by