Rows to column with comma separated

deb0687deb0687 Registered User

I want to convert table A to table B as below.

 

Table A :

 

col1

a

b

c

d

e

 

Table B:

 

col1

a,b,c,d,e

 

 

Kindly provide me a solution using only sql or any function in vertica

Comments

  • Navin_CNavin_C Registered User

    How about using group_concat UDx in Vertica.

     

    Example usage :

     

    create table test_comma_concat
    (col1 varchar)

    insert into test_comma_concat values('a');
    insert into test_comma_concat values('b');
    insert into test_comma_concat values('c');
    insert into test_comma_concat values('d');

    select * from test_comma_concat

    Using group_concat function :

     

    nnani=> select group_concat(col1) over () from test_comma_concat;
    list
    ------------
    b, d, a, c
    (1 row)

     

    You can get this UDx from Vertica Marketplace

     

     

  • deb0687deb0687 Registered User

    Hi Navin,

     

    I am unable to get group_concat UDx in Vertica.

     

    Can you please download and send that to me here as an attachment.

     

     

     

     

     

  • SruthiASruthiA Employee, Registered User, VerticaExpert

    Hi,

     

      You can download the strings_package from the URL https://github.com/vertica/Vertica-Extension-Packages/tree/master/strings_package

     

    Group_concat is present in strins_package. Instructions on how to install package are present in the above given URL.

     

    -Regards,

     Sruthi

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file