pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Emi Lu <emilu@encs.concordia.ca>
To: pgsql-sql@postgresql.org
Subject: A sys func for a->b,   b->c =>     a->c ?
Date: Wed, 02 Apr 2008 10:21:48 -0400
Message-ID: <47F3967C.9070104@encs.concordia.ca> (raw)

Good Morning,

Someone has better solution about the following query situation?

table test with two columns with primary key (id1, id2)
id1, id2
=========
1    2
1    3
12   3
13   5



Query conditions:
=====================
(1) a->b  => b->a
(2) a->b and a->c => a->c



Expected return:
id1   id2
===========
1     2
1     3
1    12

2    1
2    3
2    12

3    1
3    2
3    12

12   1
12   2
12   3

13   5


I did:

create view v_test AS
select id1 , id2 from test
union
select id2, id1  from test;


(
SELECT    a.id1 , b.id2
FROM      v_test AS a
left join v_test AS b
    ON (a.id2 = b.id1)
WHERE a.id1 <> b.id2
)
UNION
(
SELECT id1, id2
FROM   v_test
)
order by id1 ;


The query is a bit complex, do we have a better system func or query for 
this?

Thanks a lot!



Message-ID: <47F3967C.9070104@encs.concordia.ca>
Permalink:  ../47F3967C.9070104@encs.concordia.ca/
Also on:    postgresql.org/message-id/47F3967C.9070104@encs.concordia.ca

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: emilu@encs.concordia.ca
  Subject: Re: A sys func for a->b,   b->c =>     a->c ?
  In-Reply-To: <47F3967C.9070104@encs.concordia.ca>

* 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