Tree structure
Tree structure
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.
Any help would be appreciated.
Ben.
Re: Tree structure
Normally it's done with self-relation. You need a table with "ID" and "PARENT_ID". PARENT_ID will contain null for root level and other row's ID for children. One warning: going through such tree could be slow. I don't know is there anything PostgreSQL specific that might help. I know that Oracle have a special tree command.
At 14:27 11.9.2000 , 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.
Any help would be appreciated.
Ben.
Re: Tree structure
Thanks for your offer, I'll be very interested to see how you did that. I also found very interesting solution at http://www.dbmsmag.com/9603d06.html http://www.dbmsmag.com/9604d06.html http://www.dbmsmag.com/9605d06.html At 11:22 12.9.2000 , kovacsz wrote: >We are using tree structures (and partially ordered trees) with >PostgreSQL. After the beginning success we got into speed problems. With >special plus tables, triggers and functions now we have a reasonably fast >database which contains about 5-10 tree structures. If you are interested, >I may send you some of these part of our database. But, PostgreSQL "from >base" doesn't support tree structures, neither recursions (like in SQL3), >as far as I know (see TODO list).
RE: Tree structure
Any details you can supply would be appreciated. I have got a table at the moment as:
id | group_name | parentid
-------------------------------
1 | Main |
2 | Group |
3 | User |
4 | Group1 | 1
5 | Group2 | 1
6 | Group2-1 | 5Just for testing. I can see how it should work but the client side code is defeating me at the moment. I'm working in delphi with winzeos (cracking components by the way). Anyone done this.
Thanks for any help
Ben Trewern
> -----Original Message-----
> From: kovacsz [mailto:zoli@pc10.radnoti-szeged.sulinet.hu]
> Sent: 12 September 2000 10:23
> To: Zeljko Trogrlic
> Cc: Trewern, Ben; 'pgsql-sql@postgresql.org'
> Subject: Re: [SQL] Tree structure
>
>
> We are using tree structures (and partially ordered trees) with
> PostgreSQL. After the beginning success we got into speed
> problems. With
> special plus tables, triggers and functions now we have a
> reasonably fast
> database which contains about 5-10 tree structures. If you
> are interested,
> I may send you some of these part of our database. But,
> PostgreSQL "from
> base" doesn't support tree structures, neither recursions
> (like in SQL3),
> as far as I know (see TODO list).
>
Re: Tree structure
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 --------------------------------------------------------------------------
Odd stuff
Hi, there I hava a very odd problem, I have table named categories, it's been used for a long time, nobody change anything on it, I have a script to read it out every day, however, I got Permission deny, those script has been used for a long time. When I want to check the permission of the table by urldb=# \d categories Table "categories" Attribute | Type | Modifier -------------+-------------+----------cid | integer | not nullname | varchar(32) |code | varchar(10) |description | text |super | integer | Index: categories_pkey urldb=# \z categories ERROR: aclitemout: bad ai_idtype: 53 What this message means? -- Jie LIANG Internet Products Inc. 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 jliang@ipinc.com www.ipinc.com