Removing duplicates from multiple self left joins - Mailing list pgsql-general

From James Moriarty
Subject Removing duplicates from multiple self left joins
Date
Msg-id AANLkTimyMLaBO6RMjSEBW-gdovdh+g13J=QfuoBz_LtT@mail.gmail.com
Whole thread Raw
List pgsql-general
I am dynamically generating a query like below that creates different combinations of rules by left joining (any number of times) on itself and avoiding rules with some of the same attributes as part of the joins conditions e.g. 
 
    SELECT count(*) 
    FROM rules AS t1 
    LEFT JOIN rules AS t2
     ON t1.id != t2.id
     AND ...
    LEFT JOIN rules AS t3
     ON t1.id != t2.id AND t1.id != t3.id AND t2.id != t3.id
     AND ...

I am currently removing duplicates by creating an array of ids from the joined rows then sorting and grouping by them:

    SELECT sort(array[t1.id, t2.id, t3.id]) 
    ...
    GROUP BY ids

I would like to know if there is a better way of removing duplicate rows e.g.

    t1.ID | t2.ID | t3.ID
    ---------------------
      A   |   B   |   C
      C   |   B   |   A

Should be

    t1.ID | t2.ID | t3.ID
    ---------------------
      A   |   B   |   C

Or

    t1.ID | t2.ID | t3.ID
    ---------------------
      C   |   B   |   A

But not both.

I would like to go from a permutation of rows to a combination rows.

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Fwd: [pgsql-www] Forums at postgresql.com.au
Next
From: Adarsh Sharma
Date:
Subject: What is Dialect