Re: How to generate unique invoice numbers for each day

From: Jorge Godoy <jgodoy(at)gmail(dot)com>
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-15 18:41:08
Message-ID: AANLkTikLJ6Obct==F7QyH45r7XijrU9L0bLaQN+qctaT@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Use a sequence.

--
Jorge Godoy <jgodoy(at)gmail(dot)com>

2011/1/15 Andrus Moor <kobruleht2(at)hot(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus Moor 2011-01-15 19:09:06 Re: How to generate unique invoice numbers foreach day
Previous Message Andrus Moor 2011-01-15 18:13:11 How to generate unique invoice numbers for each day