Re: contrib/tablefunc/connectby question

From: Joe Conway <mail(at)joeconway(dot)com>
To: sector119(at)mail(dot)ru
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: contrib/tablefunc/connectby question
Date: 2003-04-22 16:25:42
Message-ID: 3EA56D06.1070404@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

sector119(at)mail(dot)ru wrote:
> how am I able to get data field?

create table menu (id integer, parent_id integer, data text);
insert into menu values(1,null,'root');
insert into menu values(2,1,'menu 2');
insert into menu values(3,1,'menu 3');
insert into menu values(4,2,'menu 4');
insert into menu values(5,2,'menu 5');
insert into menu values(6,4,'menu 6');
insert into menu values(7,3,'menu 7');
insert into menu values(8,6,'menu 8');
insert into menu values(9,5,'menu 9');

regression=# SELECT c.*, m.data FROM connectby('menu', 'id',
'parent_id', '1', 0, '~') AS c(id int, parent_id int, level int, branch
text), menu m WHERE m.id = c.id;
id | parent_id | level | branch | data
----+-----------+-------+-----------+--------
1 | | 0 | 1 | root
2 | 1 | 1 | 1~2 | menu 2
3 | 1 | 1 | 1~3 | menu 3
4 | 2 | 2 | 1~2~4 | menu 4
5 | 2 | 2 | 1~2~5 | menu 5
6 | 4 | 3 | 1~2~4~6 | menu 6
7 | 3 | 2 | 1~3~7 | menu 7
8 | 6 | 4 | 1~2~4~6~8 | menu 8
9 | 5 | 3 | 1~2~5~9 | menu 9
(9 rows)

HTH,

Joe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2003-04-22 16:27:40 Re: Documentation
Previous Message Patrick Fiche 2003-04-22 16:24:14 Re: database browser