Search Postgresql Archives

Re: Invoice increment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 26 Feb 2020 at 09:54, Søren Frisk <soeren.frisk@xxxxxxxxx> wrote:
Hi all

I'm trying to find a way to increment an invoice number. And i think it would be pretty straight forward just using a SERIAL int. But as we're selling across multiple countries, i need the invoice increment to be reset by a country_id. any good way to achieve this in a dynamic way? 
Hope this is the right place to ask.

Hi,

Instead of a SERIAL field use INTEGER and different sequences for different countries. You can write a trigger which picks the right sequence based on the country_id and you can even use a trigger to making the new sequence for any new country_id.
However it might cause problems if you are not cautious enough. Sequences and serials not roll back their counter in case of a failing query, so you could introduce holes into your invoice numbers, which can make supervising authorities angry. :)  

Regards,
Sándor

 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux