Re: [SQL] interesting sequence

2011-07-12 Thread Kevin Crain
IF this field is unique you shouldn't get duplicates from a function; the transaction will either succeed or fail; the beauty of a function is that you can return an error message. I personally prefer to handle errors at the application level, but if you have admins running ad-hoc queries on the d

Re: [SQL] interesting sequence (Correctin)

2011-07-07 Thread Gavin Flower
On 06/07/11 21:47, Gavin Flower wrote: I forgot the format required of the order number, so to get the full yesr, I should have used: to_char(day, 'MMDD') [...] v_order_num := type::text || '-' || to_char(day, 'YYMMDD') ||

Re: [SQL] interesting sequence

2011-07-06 Thread Gavin Flower
On 06/07/11 01:52, John Fabiani wrote: Hi, I have a special need to create a sequence like function. "O-20110704 -2" which is "O" for order (there are other types) "20110704" is for July 4, 2011 '2' the second order of the day for July 4, 2011 I of course can get the type and date. What I do

Re: [SQL] interesting sequence

2011-07-06 Thread Jasen Betts
On 2011-07-06, Kevin Crain wrote: > That's why you need to do this inside a function. Basically just make > an insert function for the table and have it calculate the count and > do the insert in one transaction. you will still get duplicates, so include code in the function to retry if there is

Re: [SQL] interesting sequence

2011-07-05 Thread Kevin Crain
That's why you need to do this inside a function. Basically just make an insert function for the table and have it calculate the count and do the insert in one transaction. On Tue, Jul 5, 2011 at 5:41 PM, Samuel Gendler wrote: > > > On Tue, Jul 5, 2011 at 2:42 PM, John Fabiani wrote: >> >> On T

Re: [SQL] interesting sequence

2011-07-05 Thread Samuel Gendler
On Tue, Jul 5, 2011 at 2:42 PM, John Fabiani wrote: > On Tuesday, July 05, 2011 01:11:11 pm Kevin Crain wrote: > > You don't need a loop there. Assuming your order id field is of type > > varchar you can just build the first part of your string and then do a > > count to get the last part using

Re: [SQL] interesting sequence

2011-07-05 Thread John Fabiani
On Tuesday, July 05, 2011 01:11:11 pm Kevin Crain wrote: > You don't need a loop there. Assuming your order id field is of type > varchar you can just build the first part of your string and then do a > count to get the last part using a LIKE comparison: > > select count(id_order) + 1 from somet

Re: [SQL] interesting sequence

2011-07-05 Thread Kevin Crain
My previous reply was intended for John. On Tue, Jul 5, 2011 at 1:11 PM, Kevin Crain wrote: > You don't need a loop there.  Assuming your order id field is of type > varchar you can just build the first part of your string and then do a > count to get the last part using a LIKE comparison: > > se

Re: [SQL] interesting sequence

2011-07-05 Thread Kevin Crain
You don't need a loop there. Assuming your order id field is of type varchar you can just build the first part of your string and then do a count to get the last part using a LIKE comparison: select count(id_order) + 1 from sometable WHERE id_order LIKE 'O-20110704 -%'; If you do this inside a

Re: [SQL] interesting sequence

2011-07-05 Thread Samuel Gendler
On Tue, Jul 5, 2011 at 6:52 AM, John Fabiani wrote: > Hi, > > I have a special need to create a sequence like function. > > "O-20110704 -2" which is > "O" for order (there are other types) > "20110704" is for July 4, 2011 > '2' the second order of the day for July 4, 2011 > > I of course can get

[SQL] interesting sequence

2011-07-05 Thread John Fabiani
Hi, I have a special need to create a sequence like function. "O-20110704 -2" which is "O" for order (there are other types) "20110704" is for July 4, 2011 '2' the second order of the day for July 4, 2011 I of course can get the type and date. What I don't know is how to get is the last numb