By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Can anyone help me to writ a function in postgresql

P: 2
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
Apr 4 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 700
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.
Apr 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.