Re: [SQL] Usage of function retruning record in query

2011-07-05 Thread gmb
gmb wrote: > > > Thanks for the feedback, Harald. > > How about specifying different aliases to the resulting values? > This will be handy when I use the same function multiple times in the same > query. > (the function will take another input parameters used in the calculations) > > E.g.: >

Re: [SQL] Usage of function retruning record in query

2011-07-05 Thread Pavel Stehule
2011/7/5 gmb : > > gmb wrote: >> >> >> Thanks for the feedback, Harald. >> >> How about specifying different aliases to the resulting values? >> This will be handy when I use the same function multiple times in the same >> query. >> (the function will take another input parameters used in the calcu

Re: [SQL] Usage of function retruning record in query

2011-07-05 Thread gmb
Pavel Stehule wrote: > > > npcps_201=# select * from (select 1,2,2,3) x (a,b,c,d); > > That is a neat trick - one I didn't know of. Thanks Pavel -- View this message in context: http://postgresql.1045698.n5.nabble.com/Usage-of-function-retruning-record-in-query-tp4549140p4552618.html Sent

[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

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

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 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

[SQL] overload

2011-07-05 Thread Viktor Bojović
Hi, while reading 20GB table through PL/PERL function , it constantly grows in RAM. I wanted to ask you which is the best way to read table inside that function without such memory consumption. Thanks in advance Code is here: CREATE FUNCTION pattern_counter("patLength" integer) RETURNS varchar

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 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

[SQL] group by with sum and sum till max date

2011-07-05 Thread M. D.
This is a little hard to explain, and I'm not sure if it's possible, but here goes. This is my query: select year, month, (select number from account where account.account_id = view_account_change.account_id) as number, (select name from account where account.account_id = view_account_change.a

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