Re: How to generate unique invoice numbers foreach day - Mailing list pgsql-general

From Andrus Moor
Subject Re: How to generate unique invoice numbers foreach day
Date
Msg-id 158067C23EF24233969A9D8B35E9BDB0@server
Whole thread Raw
In response to Re: How to generate unique invoice numbers for each day  (Jorge Godoy <jgodoy@gmail.com>)
Responses Re: How to generate unique invoice numbers foreach day
Re: How to generate unique invoice numbers foreach day
List pgsql-general
There are 365 days in year.
Do you really think pre-creating sequence for every day for every year is best solution ?
 
Andrus.
----- Original Message -----
Sent: Saturday, January 15, 2011 8:41 PM
Subject: ***SPAM*** Re: [GENERAL] How to generate unique invoice numbers foreach day

Use a sequence.

--
Jorge Godoy     <jgodoy@gmail.com>


2011/1/15 Andrus Moor <kobruleht2@hot.ee>
Invoice numbers have format  yymmddn

where n is sequence number in day staring at 1 for every day.

command

SELECT COALESCE(MAX(nullif(substring( substring(tasudok from 7), '^[0-9]*'),'')::int),0)+1
FROM invoice
where date= ?invoicedate

is used to get next free invoice number if new invoice is saved.

If multiple invoices are saved concurrently from different processes, they will probably get same number.

How to get unique invoice number for some day in 8.1+ when multiple users create new invoices ?

Andrus.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Jorge Godoy
Date:
Subject: Re: How to generate unique invoice numbers for each day
Next
From: Matthew Wilson
Date:
Subject: Need help writing exclusion constraint