Skip site navigation (1) Skip section navigation (2)

Re: Tree structure

From: "Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
To: "Trewern, Ben" <Ben(dot)Trewern(at)mowlem(dot)com>, PostgreSQL-SQL <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: Tree structure
Date: 2000-09-11 16:25:58
Message-ID: 20000911182558.A1657@frithjof (view raw or flat)
Thread:
Lists: pgsql-sql
On Mon, Sep 11, 2000 at 01:27:48PM +0100, Trewern, Ben wrote:
> Anybody know how to make a tree structure using related tables using
> Postgres.  Something like a directory structure is what I'm aiming for.  I'm
> sure there is an easy way but I'm having probs.

I am not quite sure whether this is what you are thinking about:

create table tree (
  id int4,
  parentid int4,
  data text)

A structure like

 a
 |__b
 |__c
 
can be achieved by

insert into tree (id, parentid, data) values (1, NULL, 'a');
insert into tree (id, parentid, data) values (2, 1, 'b');
insert into tree (id, parentid, data) values (3, 1, 'c');


Probably you'll also want to use a sequence for the ids, and to
declare indices on id, parentid etc.

> 
> Any help would be appreciated.
> 
> Ben.


-- 

--------------------------------------------------------------------------
Albert Reiner                                   <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
Deutsch       *       English       *       Esperanto       *       Latine
--------------------------------------------------------------------------

In response to

Responses

  • Odd stuff at 2000-09-12 18:52:34 from Jie Liang

pgsql-sql by date

Next:From: Zeljko TrogrlicDate: 2000-09-11 16:30:55
Subject: Re: Tree structure
Previous:From: Tom LaneDate: 2000-09-11 16:01:34
Subject: Re: Isolation and Concurrency in PG functions?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group