Skip to main content

Rows to column with comma separated

  • May 31, 2015
  • 3 replies
  • 7 views

deb0687
Forum|alt.badge.img+1

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

3 replies

Navin_C
Forum|alt.badge.img+2
  • Participating Frequently
  • June 1, 2015

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

 

 


deb0687
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • June 4, 2015

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.

 

 

 

 

 


SruthiA
Forum|alt.badge.img+1
  • Participating Frequently
  • June 4, 2015

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