Re: [GENERAL] is (not) distinct from - Mailing list pgsql-general

From Tom Lane
Subject Re: [GENERAL] is (not) distinct from
Date
Msg-id 1318.1488384749@sss.pgh.pa.us
Whole thread Raw
In response to Re: [GENERAL] is (not) distinct from  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: [GENERAL] is (not) distinct from
List pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> Where I am going with this, is that it is not clear to me how you are
> matching the two sets of records to determine whether they are different
> or not.

He's not.  The query is forming the cartesian product of the two tables
and then dropping join rows where the tables match ... but every B row is
going to have multiple A rows where it doesn't match, and those join rows
will all survive the WHERE.  Then "select distinct" gets rid of the
duplicates, and since nothing from A is presented in the result, it's not
very obvious what's happening.

This is a great example of "select distinct" being used as a band-aid
over a fundamental misunderstanding of SQL.  It's good advice to never use
"distinct" unless you know exactly why your query is generating duplicate
rows in the first place.

            regards, tom lane


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] is (not) distinct from
Next
From: jonathan vanasco
Date:
Subject: [GENERAL] appropriate column for storing ipv4 address