Thread: conditional joins and views

conditional joins and views

From
Jonathan Vanasco
Date:
Is it possible at all to use conditional joins in views?

ie:
    select a.* , b.* from a inner join b ON ( (a.id = b.id) AND
(a.otherfield <> ?) )

I have a few 15-20 table joins that i'd like to push into views.
i've never wanted to push something with a conditional join into a
view before, so am at a loss on this being a possibility.

seeing little documentation on this, i'm thinking its not possible
and i'll have to use a function.






// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| SyndiClick.com
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|      Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
|      RoadSound.com - Tools For Bands, Stuff For Fans
|      Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -



Re: conditional joins and views

From
Peter Eisentraut
Date:
Am Dienstag, 24. April 2007 21:43 schrieb Jonathan Vanasco:
> Is it possible at all to use conditional joins in views?
>
> ie:
>     select a.* , b.* from a inner join b ON ( (a.id = b.id) AND
> (a.otherfield <> ?) )
>
> I have a few 15-20 table joins that i'd like to push into views.
> i've never wanted to push something with a conditional join into a
> view before, so am at a loss on this being a possibility.

I think what you are looking for is a parametrized view, but that doesn't
exist.

One obvious solution is to put this into a function, but that might not have
the best performance, depending on what sort of contexts you want to use the
view in.

Another option would be using prepared statements.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/