Two serial fields question

From: Robert <robert(at)robert(dot)cz>
To: pgsql-general(at)postgreSQL(dot)org
Subject: Two serial fields question
Date: 2000-01-17 23:38:50
Message-ID: 3883A80A.C2F69C8D@robert.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

what's the best way to insert a new invoice to the following table

create table invoice_table (
id serial;
number int;
year int;
)

The problem is of course that 'number' is unique only in the given year
so I'd need to lock table and do something like

insert into invoice_table (number,year) values (max(...)+1,2000)

I guess this is fairly common problem, what's the best/standard PG way
of
doing it? Thanks for your help.

- Robert

Responses

Browse pgsql-general by date

  From Date Subject
Next Message ANURADHA PAIDARKAR 2000-01-18 04:46:43 Re: [GENERAL] confusion with vacuum commnad.
Previous Message Martin Schulze 2000-01-17 23:02:45 Re: Comments in postgres ?