Received: from frithjof.reiner (qmailr@c41.dialin.tuwien.ac.at [192.35.243.51]) by hub.org (8.10.1/8.10.1) with SMTP id e8CG1eS72312 for ; Tue, 12 Sep 2000 12:01:40 -0400 (EDT) Received: (qmail 1721 invoked by uid 500); 11 Sep 2000 16:25:58 -0000 From: "Albert REINER" Date: Mon, 11 Sep 2000 18:25:58 +0200 To: "Trewern, Ben" , PostgreSQL-SQL Subject: Re: Tree structure Message-ID: <20000911182558.A1657@frithjof> Mail-Followup-To: "Trewern, Ben" , PostgreSQL-SQL References: <996802F75C3CD411B424001083FA445B0594B0@CET_PONXX_FP001> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.6i In-Reply-To: <996802F75C3CD411B424001083FA445B0594B0@CET_PONXX_FP001>; from Trewern, Ben on Mon, Sep 11, 2000 at 01:27:48PM +0100 X-Archive-Number: 200009/78 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 Deutsch * English * Esperanto * Latine --------------------------------------------------------------------------