Re: help on creating table

From: "Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
To: pgsql-sql <pgsql-sql(at)fc(dot)emc(dot)com(dot)ph>, PostgreSQL-SQL <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: help on creating table
Date: 2000-10-24 21:15:10
Message-ID: 20001024231510.B1062@frithjof
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Saluton,

this is easy:

On Fri, Oct 20, 2000 at 06:48:54PM +0800, pgsql-sql wrote:
...
> NODE1
> + --- NODE1_1
> + --- NODE1_2
> | + --- NODE1_2_1
> + --- NODE1_3

create table n (id int4, parent int4, data text);

insert into n (id, data) values (1, 'node 1');
insert into n (id, parent, data) values (2, 1, 'node 1.1');
insert into n (id, parent, data) values (3, 1, 'node 1.2');
insert into n (id, parent, data) values (4, 3, 'node 1.2.1');
insert into n (id, parent, data) values (5, 1, 'node 1.3');

(you will probably want to use a serial for id, etc.)

The idea is to store each node in a row, and to store both the row's
id and the id of the parent node in it. When there is no parent node
(your node NODE_1), parent is NULLL.

HTH,

Albert.

--

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Poul L. Christiansen 2000-10-24 21:22:20 Re: Error in Extrack Database
Previous Message Mark Volpe 2000-10-24 20:39:54 Re: [SQL] Re: NULL