pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Albert REINER <areiner@tph.tuwien.ac.at>
To: Trewern, Ben <Ben.Trewern@mowlem.com>
To: PostgreSQL-SQL <pgsql-sql@postgreSQL.org>
Subject: Re: Tree structure
Date: Mon, 11 Sep 2000 18:25:58 +0200
Message-ID: <20000911182558.A1657@frithjof> (raw)
In-Reply-To: <996802F75C3CD411B424001083FA445B0594B0@CET_PONXX_FP001>
References: <996802F75C3CD411B424001083FA445B0594B0@CET_PONXX_FP001>

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@tph.tuwien.ac.at>
Deutsch       *       English       *       Esperanto       *       Latine
--------------------------------------------------------------------------



view thread (5+ messages)  latest in thread

Message-ID: <20000911182558.A1657@frithjof>
Permalink:  ../20000911182558.A1657@frithjof/
Also on:    postgresql.org/message-id/20000911182558.A1657@frithjof

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: areiner@tph.tuwien.ac.at, Ben.Trewern@mowlem.com
  Subject: Re: Tree structure
  In-Reply-To: <20000911182558.A1657@frithjof>
  References: <996802F75C3CD411B424001083FA445B0594B0@CET_PONXX_FP001> <20000911182558.A1657@frithjof>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox