Solved! Was (Return t/f on existence of a join) - Mailing list pgsql-general

From Madison Kelly
Subject Solved! Was (Return t/f on existence of a join)
Date
Msg-id 46F42A73.6060106@alteeve.com
Whole thread Raw
In response to Re: Return t/f on existence of a join  (Erik Jones <erik@myemma.com>)
Responses Wait, not solved... Was (Return t/f on existence of a join)  (Madison Kelly <linux@alteeve.com>)
List pgsql-general
Thanks to both of you, Erik and Jon!

   I had to tweak your two replies to get what I wanted (all 'foo' rows
returned, was only getting ones with a match in 'baz'). You two sent me
on the right path though and I was able to work out the rest using the
PgSQL docs on 'CASE' and 'JOIN'.

   Here is the working query (where 'bar_id'=2):

SELECT
    CASE z.baz_bar_id
    WHEN 2
        THEN TRUE
        ELSE FALSE
    END AS tf_col,
    f.foo_id
FROM foo f
    LEFT OUTER JOIN baz z
    ON (f.foo_id=z.baz_foo_id)
    LEFT OUTER JOIN bar b
    ON (b.bar_id=z.baz_bar_id)
AND
    b.bar_id=2;

   Thanks kindly to both! I honestly didn't expect to work this out
before then end of the day. Cool!

Madi

pgsql-general by date:

Previous
From: Alex Vinogradovs
Date:
Subject: SPI shared memory ?
Next
From: Jon Sime
Date:
Subject: Re: Return t/f on existence of a join