Connecting Tech Pros Worldwide Forums | Help | Site Map

Can anyone help me to writ a function in postgresql

Newbie
 
Join Date: Apr 2008
Location: India
Posts: 2
#1: Apr 4 '08
Hi Everyone
I've worked with Postgres Database but i havn't written any user defined function.now i want to produce some reports so can anyone help me to write the function to get my report please see the following details.

In table i have following Data
Batch No OrderNo

127 81294
127 80009
128 13344
129 80379
130 82534
131 25626
132 69103
132 69102
132 64753


I want to produce Report Like this from postgres DataBase
Batch No OrderNo

127 81294,80009
128 13344
129 80379
130 82534
131 25626
132 69103,69102,64753
Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 292
#2: Apr 4 '08

re: Can anyone help me to writ a function in postgresql


Quote:

Originally Posted by annielucinda

Hi Everyone
I've worked with Postgres Database but i havn't written any user defined function.now i want to produce some reports so can anyone help me to write the function to get my report please see the following details.

In table i have following Data
Batch No OrderNo

127 81294
127 80009
128 13344
129 80379
130 82534
131 25626
132 69103
132 69102
132 64753


I want to produce Report Like this from postgres DataBase
Batch No OrderNo

127 81294,80009
128 13344
129 80379
130 82534
131 25626
132 69103,69102,64753

Do you really need a function? You can do it by a onr query like this (test2 is your table name)
Expand|Select|Wrap|Line Numbers
  1. select distinct  i as BatchNo, array_to_string((array(select j from test2 where i=k.i)),',') as OrderNo from test2 k;
  2.  
If you want i can write you a function doing the same job.
Reply