I have a table with two columns. Each row in this table is the edge in the graph:
v | w
-------
a a
a b
a c
b d
b b
c c
e f
g e
h h
I need to collect all edges that are connected together:
result
-------
a,b,c,d
e,f,g
h
What is the best way to do it? Create a cursor and loop over the table and collect all edges to the temporary table ? Or may be there are functions to make this tasks more convenient way ?
Updated:
create table tt (
v text,
w text
);
insert into tt values('a', 'a');
insert into tt values('a', 'b');
insert into tt values('a', 'c');
insert into tt values('d', 'd');
insert into tt values('b', 'b');
insert into tt values('c', 'c');
insert into tt values('e', 'f');
insert into tt values('g', 'e') ;
insert into tt values('h', 'h') ;