How to writ function in postgres?

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

    How to writ function in postgres?

    Plz can any one help me to write function in postgres

    i have a table with two columns
    for example student class and student name

    the table Data is like this
    STU_class Name
    1 Ann
    2 JAck
    3 Dickson
    1 Donald

    but the report i need is in the following format

    Class Name
    1 Ann,Donald
    2 JacK
    3 Dickson

    can anyone help me to generate this report

    Thanks in advance
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Originally posted by annielucinda
    Plz can any one help me to write function in postgres

    i have a table with two columns
    for example student class and student name

    the table Data is like this
    STU_class Name
    1 Ann
    2 JAck
    3 Dickson
    1 Donald

    but the report i need is in the following format

    Class Name
    1 Ann,Donald
    2 JacK
    3 Dickson

    can anyone help me to generate this report

    Thanks in advance
    Suppose table name is test, i think it is the solution
    Code:
    select distinct  i as class, array_to_string((array(select j from test where i=k.i)),',') as name from test k;

    Comment

    Working...