pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gibson Chimhamhiwa <gchimhamhiwa@gmail.com>
To: pgsql-admin@postgresql.org
Subject: Prent-Child relationships in SQL
Date: Fri, 25 Jul 2008 13:42:38 +0200
Message-ID: <f2b0d8200807250442j480e6021l53267e90280e5bc0@mail.gmail.com> (raw)

Hi All,

I have a simple table below and I want to be able to write a SQL select
query that returns the grouping_ids until I get no more children. The
parent_grouping_id column is the parent to the grouping_id child column. Can
somebody please advise me how I can do this in postgreSQL.

CREATE TABLE grouping
(
  grouping_id int4 NOT NULL,
  version int4,
  parent_grouping_id int4,
  topic_topic_id int4,
  CONSTRAINT grouping_pkey PRIMARY KEY (grouping_id),
  CONSTRAINT fk1e2e9d036852722d FOREIGN KEY (topic_topic_id)
      REFERENCES topic (topic_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk1e2e9d03a1bfbfe FOREIGN KEY (topic_topic_id)
      REFERENCES topic (topic_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk1e2e9d03cdaf7222 FOREIGN KEY (parent_grouping_id)
      REFERENCES grouping (grouping_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITHOUT OIDS;
ALTER TABLE grouping OWNER TO napdba;

Thanks In Advance.

view thread (2+ messages)  latest in thread

Message-ID: <f2b0d8200807250442j480e6021l53267e90280e5bc0@mail.gmail.com>
Permalink:  ../f2b0d8200807250442j480e6021l53267e90280e5bc0@mail.gmail.com/
Also on:    postgresql.org/message-id/f2b0d8200807250442j480e6021l53267e90280e5bc0@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: gchimhamhiwa@gmail.com
  Subject: Re: Prent-Child relationships in SQL
  In-Reply-To: <f2b0d8200807250442j480e6021l53267e90280e5bc0@mail.gmail.com>
  References: <f2b0d8200807250442j480e6021l53267e90280e5bc0@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox