Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-02 Thread Greg Stark
On Thu, Jul 2, 2009 at 10:35 AM, Scott Marlowe wrote: > Actually, since > you're only incrementing from the highest one, you could just lock the > id from a select max(orderid) where custid=xyz and you'd only have to > lock one row. Not really because you would have a race condition between select

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-02 Thread Scott Marlowe
On Thu, Jul 2, 2009 at 3:28 AM, Greg Stark wrote: >> On Wed, Jul 1, 2009 at 6:01 PM, Scott Marlowe wrote: >>> The simplest method is to do something like: >>> >>> begin; >>> select * from sometable where cust_id=99 order by order_id desc for update; >>> >>> to lock all the customer records for cust

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-02 Thread Greg Stark
On Thu, Jul 2, 2009 at 2:46 AM, Merrick wrote: > I was hoping there would be a way to add a field the sequence table > postgresql automatically generates so I could rely on whatever > mechanism postgresql uses to avoid the problems described thus far. Hm, well you could create a sequence for every

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-01 Thread Merrick
Thank you, this helps get me on the right path. On Wed, Jul 1, 2009 at 7:12 PM, Scott Marlowe wrote: > On Wed, Jul 1, 2009 at 7:46 PM, Merrick wrote: >> I was hoping there would be a way to add a field the sequence table >> postgresql automatically generates so I could rely on whatever >> mechanis

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-01 Thread Scott Marlowe
On Wed, Jul 1, 2009 at 7:46 PM, Merrick wrote: > I was hoping there would be a way to add a field the sequence table > postgresql automatically generates so I could rely on whatever > mechanism postgresql uses to avoid the problems described thus far. > > I should have included more info, it's high

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-01 Thread Scott Marlowe
I'm sure a trigger could be written to do what I just said. On Wed, Jul 1, 2009 at 7:46 PM, Merrick wrote: > I was hoping there would be a way to add a field the sequence table > postgresql automatically generates so I could rely on whatever > mechanism postgresql uses to avoid the problems descri

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-01 Thread Merrick
I was hoping there would be a way to add a field the sequence table postgresql automatically generates so I could rely on whatever mechanism postgresql uses to avoid the problems described thus far. I should have included more info, it's highly likely that multiple users will be accessing using sa

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-01 Thread Scott Marlowe
On Wed, Jul 1, 2009 at 6:04 PM, Merrick wrote: > I have been using postgresql for 8 years in web projects and ran into > a problem that I could not find a solution for in the archives or > through Google. > > Here is a generalized example of what I want to happen. I have a > customers table, and an

Re: [GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-01 Thread Greg Stark
On Thu, Jul 2, 2009 at 1:04 AM, Merrick wrote: > I would like for each customer > to have orders that start at 1 and move up sequentially. I realize > it's probably not efficient to create a new sequence for each > customer, so am looking for alternate ways to accomplish the same > thing. You coul

[GENERAL] 1 Sequence per Row i.e. each customer's first order starts at 1

2009-07-01 Thread Merrick
I have been using postgresql for 8 years in web projects and ran into a problem that I could not find a solution for in the archives or through Google. Here is a generalized example of what I want to happen. I have a customers table, and an orders table. I would like for each customer to have orde