Re: Coditional join of query using PostgreSQL

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Nick Dro <postgresql(at)walla(dot)co(dot)il>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Coditional join of query using PostgreSQL
Date: 2017-05-15 19:45:40
Message-ID: 57AF6AB9-3064-4702-A775-29EC4E0926ED@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On 15 May 2017, at 19:02, Nick Dro <postgresql(at)walla(dot)co(dot)il> wrote:
>
> Hi,
> I'm new to postgresql and couldn't find answer to this situation anywhere.
> I asked this here:
> http://stackoverflow.com/questions/43984208/coditional-join-of-query-using-postgresql
>
> I hope there is a better solution rather than creating two separated functions :(

You can use your boolean parameter inside the join condition:
[…] on (tfquery.a = main.a and ((type_f and tfquery.d = main.d) or not type_f))

Beware that you don't also have a column named type_f in that join somewhere.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ken Tanzer 2017-05-15 19:55:48 Help: Installing 9.6 breaks local connections to 9.2 on Centos 6.9
Previous Message Dmitry Dolgov 2017-05-15 19:35:27 Re: Insert performance and disk usage in JSON vs JSONB