pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Prent-Child relationships in SQL
2+ messages / 2 participants
[nested] [flat]

* Prent-Child relationships in SQL
@ 2008-07-25 11:42 Gibson Chimhamhiwa <gchimhamhiwa@gmail.com>
  2008-07-25 13:13 ` Re: Prent-Child relationships in SQL Igor Neyman <ineyman@perceptron.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Gibson Chimhamhiwa @ 2008-07-25 11:42 UTC (permalink / raw)
  To: pgsql-admin

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.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Prent-Child relationships in SQL
  2008-07-25 11:42 Prent-Child relationships in SQL Gibson Chimhamhiwa <gchimhamhiwa@gmail.com>
@ 2008-07-25 13:13 ` Igor Neyman <ineyman@perceptron.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Igor Neyman @ 2008-07-25 13:13 UTC (permalink / raw)
  To: Gibson Chimhamhiwa <gchimhamhiwa@gmail.com>; pgsql-admin

Read the docs on "connectby" function provided by "tablefunc" contrib
module.
 
Igor

________________________________

From: pgsql-admin-owner@postgresql.org
[mailto:pgsql-admin-owner@postgresql.org] On Behalf Of Gibson
Chimhamhiwa
Sent: Friday, July 25, 2008 7:43 AM
To: pgsql-admin@postgresql.org
Subject: [ADMIN] Prent-Child relationships in SQL


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.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2008-07-25 13:13 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-07-25 11:42 Prent-Child relationships in SQL Gibson Chimhamhiwa <gchimhamhiwa@gmail.com>
2008-07-25 13:13 ` Igor Neyman <ineyman@perceptron.com>

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