Two serial fields question - Mailing list pgsql-general

From Robert
Subject Two serial fields question
Date
Msg-id 3883A80A.C2F69C8D@robert.cz
Whole thread Raw
List 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

pgsql-general by date:

Previous
From: Martin Schulze
Date:
Subject: Re: Comments in postgres ?
Next
From: ANURADHA PAIDARKAR
Date:
Subject: Re: [GENERAL] confusion with vacuum commnad.