Friday, 15 April 2011

stored procedures - How to combine a CASE statement with a LATERAL JOIN in PostgreSQL? -


I need to call the function multiple times for each selection row, because the function has several out parameters, which I need Select

example

  SELECT a, b, (from func (a)), choose from (func (a) 2) From table 1 to  

To call this function only once I use to join in the background

  SELECT a, b, lat.out1, lat.out2 LEFT OUTER Join Later (Select Out 1, Out 2 F The font is thrown on (a)) Let's (TRUE)  

problem a is the func throwing exception with being called Then it happens without it I will have to do it

  Select one, b, case when there is no function, then from the fon (a) end, case when no funnel is out Does not occur a) End of table 1  

but how do I use it in joining the side ? Is there a way to use CASE to join the side? Or is there any other way of calling the process only once? Good question you can create a wrapper function which is

/ P>
  function wrap_func (an integer) returns $$ as the return table (out1 int, out2 int) if a blank is returned; end if; Return query (out1, out2 choose from func (a)); End; $$ language plpgsql;  

If you call the cover in your side , then it will behave as you expect.


No comments:

Post a Comment