Re: Can't seem to mix an inner and outer join in a query and get it to work right.

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: David Gauthier <davegauthierpg(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Can't seem to mix an inner and outer join in a query and get it to work right.
Date: 2020-07-01 18:25:34
Message-ID: CAKFQuwbmk4R9yBYy+EE9+=5PeNx3rWrGsDfqEFLOEBe3wLGMpA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The convention here is to bottom post or inline responses.

On Wed, Jul 1, 2020 at 9:51 AM David Gauthier <davegauthierpg(at)gmail(dot)com>
wrote:

> Actually, I want the outer join first. If it finds something, then move
> on to the inner join and filter out all those that don't join to a rec with
> 'autosmoke'. But if the outer join does not connect to the workarea_env
> table, then just return what you have (the purpose of the outer join)
>
>>
>>>
So your final result - ignoring columns - is basically:
(sqf, (workarea, events))

where either the entire (workarea, events) is null, or if it is
non-null then workarea must also be non-null

Thus: ((workarea is left joined against events) with the whole thing left
joined against sqf). And we are back to the join ordering precedence since
what you originally wrote was ((sqf, workarea), events).

In short - two outer joins; you can work out precedence either with
syntactic order or parentheses.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message FOUTE K. Jaurès 2020-07-01 18:25:48 Re: PostgreSQL 12 - ERROR: could not rename file "pg_logical/snapshots/1A-7C00D890.snap.13594.tmp" to "pg_logical/snapshots/1A-7C00D890.snap": No space left on device
Previous Message FOUTE K. Jaurès 2020-07-01 18:21:58 Re: PostgreSQL 12 - ERROR: could not rename file "pg_logical/snapshots/1A-7C00D890.snap.13594.tmp" to "pg_logical/snapshots/1A-7C00D890.snap": No space left on device