Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-17 Thread Chris Browne
m...@smogura.eu (Radosław Smogura) writes: > In any approach preventing gaps, locking is required. This is real life > situation; imagine you have two coworkers and then they need to create > invoices, so they looks in ledger (or a last day copy of ledger in their > offices; international compan

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Thomas Kellerer
Tomas Vondra wrote on 16.01.2011 23:41: Yes, locking may in some cases lead to deadlocks, that's true. For example creating several invoices (for different days) in a single transaction may lead to a deadlock. But that's a feature, not a bug. Hmm, a single transaction cannot deadlock itself as

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Tomas Vondra
Dne 16.1.2011 22:44, Andrus Moor napsal(a): > Thank you. > >> 2. In point 2. add FOR UPDATE >> 3. Use READ COMMITED TRANSACTION ISOLATION LEVEL >> >> Don't lock tables, You wrote you can generate invoices for few days >> backward, >> so you don't need locking whole table. >> >> Don't use seqences,

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Andrus Moor
Thank you. 2. In point 2. add FOR UPDATE 3. Use READ COMMITED TRANSACTION ISOLATION LEVEL Don't lock tables, You wrote you can generate invoices for few days backward, so you don't need locking whole table. Don't use seqences, as sequence value will don't get back when transaction is rolled ba

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Radosław Smogura
I will sugest to: 1. Delete point 1. 2. In point 2. add FOR UPDATE 3. Use READ COMMITED TRANSACTION ISOLATION LEVEL Don't lock tables, You wrote you can generate invoices for few days backward, so you don't need locking whole table. Don't use seqences, as sequence value will don't get back when

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Alban Hertroys
On 16 Jan 2011, at 18:56, Andrus Moor wrote: > My Visual FoxPro application works OK in this case. > I used FLOCK() to lock invoice header table (FLOCK() waits indefinitely until > lock is obtained and reads fresh data from disk), > > used > > SELECT MAX( CAST( SUBSTRING(invoiceno,8) AS INT )

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Andrus Moor
Yes. This is customer requirement and I cannot change it. OR... can you go back to your customer and tell them they wont like this. Really really they should let you do it correctly. I find people dont change because they dont have to, not because there is an actual reason. Many times, given a

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Andy Colson
On 01/16/2011 11:00 AM, Andrus Moor wrote: Andy, 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

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Andrus Moor
Andy, 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

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Andy Colson
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

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-16 Thread Tomas Vondra
Dne 16.1.2011 03:29, Jasen Betts napsal(a): > On 2011-01-15, 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),

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-15 Thread Peter Geoghegan
This is an very common and well understood problem. Take a look at this: http://www.varlena.com/GeneralBits/130.php -- Regards, Peter Geoghegan -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-g

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-15 Thread Jasen Betts
On 2011-01-15, 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

Re: [GENERAL] How to generate unique invoice numbers for each day

2011-01-15 Thread Jorge Godoy
Use a sequence. -- Jorge Godoy 2011/1/15 Andrus Moor > 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

[GENERAL] How to generate unique invoice numbers for each day

2011-01-15 Thread Andrus Moor
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 i