Re: left join + case - how is it processed?

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: Chris <dmagick(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: left join + case - how is it processed?
Date: 2009-01-19 16:51:05
Message-ID: 396486430901190851m2d4f3e73hbcb77a543d88044e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Sun, Jan 18, 2009 at 7:30 PM, Chris <dmagick(at)gmail(dot)com> wrote:

> I have a view that looks like this:
>
> SELECT
> CASE
> WHEN r.assetid IS NULL THEN p.assetid
> ELSE r.assetid
> END AS assetid,
> CASE
> WHEN r.userid IS NULL THEN p.userid
> ELSE r.userid
> END AS userid, p.permission, p."granted", p.cascades
> FROM sq_ast_perm p
> LEFT JOIN sq_vw_ast_role r ON r.roleid::text = p.userid::text AND
> r.assetid::text = p.assetid::text;

The effect that you are trying to achieve with CASE statements is
better suited to the COALESCE(...) function.
http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AEN14484

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Akos Gabriel 2009-01-19 17:31:26 test
Previous Message Tom Lane 2009-01-19 16:33:34 Re: left join + case - how is it processed?