Re: self referencing table. - Mailing list pgsql-general

From Ondrej Ivanič
Subject Re: self referencing table.
Date
Msg-id CAM6mieJrw0v7fJbuyOOTT0pzGtT58+EHRDycqdRp87p9wueFrA@mail.gmail.com
Whole thread Raw
In response to self referencing table.  (David Salisbury <salisbury@globe.gov>)
List pgsql-general
Hi,

On 18 January 2012 11:31, David Salisbury <salisbury@globe.gov> wrote:
>
> I've got a table:
>
>               Taxa
>     Column     |            Type
> ----------------+-----------------------------
> id              | integer                     |
> parent_id       | integer                     |
> taxonomic_rank  | character varying(32)       |
> latin_name      | character varying(32)
>
> It's basically a self referential table, with
> values in the taxonomic_rank like

You should check Joe Celko's book: Trees and hierarchies in SQL for smarties
It has many good ideas about storing and accessing tree-like
structures in relational databases. (just google for chapter names
:)). I have this link in my bookmarks but it doesn't work anymore:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html --
quite good article about nested sets

For example in "nested sets" model finding the path is simple query like this:
SELECT taxonomic_rank FROM Taxa WHERE lft < $left AND rgt > $right
ORDER BY lft ASC;
where $left, $right are lft and rgt values from required taxa.id

--
Ondrej Ivanic
(ondrej.ivanic@gmail.com)

pgsql-general by date:

Previous
From: Fujii Masao
Date:
Subject: Re: [ADMIN] PG synchronous replication and unresponsive slave
Next
From: Manoj Govindassamy
Date:
Subject: Re: [ADMIN] PG synchronous replication and unresponsive slave