Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old April 4th, 2008, 12:16 PM
Newbie
 
Join Date: Apr 2008
Location: India
Age: 24
Posts: 2
Default Can anyone help me to writ a function in postgresql

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
Reply
  #2  
Old April 4th, 2008, 03:20 PM
Moderator
 
Join Date: Dec 2006
Posts: 250
Default

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
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles