Re: self referencing table.

From: Ondrej Ivanič <ondrej(dot)ivanic(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: self referencing table.
Date: 2012-01-18 01:20:47
Message-ID: CAM6mieJrw0v7fJbuyOOTT0pzGtT58+EHRDycqdRp87p9wueFrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

On 18 January 2012 11:31, David Salisbury <salisbury(at)globe(dot)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(dot)ivanic(at)gmail(dot)com)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Manoj Govindassamy 2012-01-18 01:54:04 Re: PG synchronous replication and unresponsive slave
Previous Message Fujii Masao 2012-01-18 01:04:47 Re: PG synchronous replication and unresponsive slave