From: | Andy Colson <andy(at)squeakycode(dot)net> |
---|---|
To: | Andrus Moor <kobruleht2(at)hot(dot)ee> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to generate unique invoice numbers for each day |
Date: | 2011-01-16 16:08:57 |
Message-ID: | 4D331819.4080508@squeakycode.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 01/15/2011 12:13 PM, Andrus Moor wrote:
> 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.
>
I understand this is a business rule, and you cant change it.
My opinion is you are doing it wrong. Don't encode more than one bit of data into one column. You have two bits of data, date and invoice number. Use TWO columns! Let the invoice number auto-inc and never reset it. You want to find invoices on some day, query the date field. You want to find a specific invoice, query the invoice number. Dont combine the two. Why write a bunch of bug ridden code that encodes and decodes the two fields into one?
But I know... you cant change it. Someone up the chain thinks its just the bee's knees. I had to say it though. Its been said. I will go in peace.
-Andy
From | Date | Subject | |
---|---|---|---|
Next Message | Jon Smark | 2011-01-16 16:40:45 | Re: Record with a field consisting of table rows |
Previous Message | Tomas Vondra | 2011-01-16 15:46:54 | Re: How to generate unique invoice numbers for each day |