Can anyone help me to writ a function in postgresql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • annielucinda
    New Member
    • Apr 2008
    • 2

    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,647 53
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    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,647 53
    Do you really need a function? You can do it by a onr query like this (test2 is your table name)
    Code:
    select distinct  i as BatchNo, array_to_string((array(select j from test2 where i=k.i)),',') as OrderNo from test2 k;
    If you want i can write you a function doing the same job.

    Comment

    Working...