Re: Postgres views cannot use both union and join/where - Mailing list pgsql-performance

From David G. Johnston
Subject Re: Postgres views cannot use both union and join/where
Date
Msg-id CAKFQuwZ+L+HLFs0Fdz2W4NYYxxk6Ko1CMQFyo-c1-ba-VuqDkA@mail.gmail.com
Whole thread Raw
In response to Re: Postgres views cannot use both union and join/where  (Michael Lewis <mlewis@entrata.com>)
Responses Re: Postgres views cannot use both union and join/where
List pgsql-performance
On Tuesday, October 19, 2021, Michael Lewis <mlewis@entrata.com> wrote:
On Tue, Oct 19, 2021 at 3:48 PM Mithran Kulasekaran <mithranakulasekaran@gmail.com> wrote:
create  view template_view (id, name, description, is_staged) as
select t.id,t.name, t.description, false as is_staged
from template t
left join template_staging ts on t.name = ts.name and ts.name is null

Does that work? I've only seen that type of logic written as-

left join template_staging ts on t.name = ts.name
where ts.name is null

The are functionally equivalent, though the timing of the expression evaluation differs slightly.

It could also be written as an anti-join:

Select * from template as t where not exists (select 1 from template_staging as ts where t.name = ts.name)

David J.

pgsql-performance by date:

Previous
From: Michael Lewis
Date:
Subject: Re: Postgres views cannot use both union and join/where
Next
From: Ashkil Dighin
Date:
Subject: Re: Lock contention high