Re: Using case or if to return multiple rows - Mailing list pgsql-sql

From Pavel Stehule
Subject Re: Using case or if to return multiple rows
Date
Msg-id 162867790707120009i7b63994l8df60afd6b9a66f9@mail.gmail.com
Whole thread Raw
In response to Using case or if to return multiple rows  ("Ashish Karalkar" <ashish.karalkar@info-spectrum.com>)
List pgsql-sql
Hello

what is relation between t1 and t3 and t2 and t3? Which row from t3
specifies  value?  You cannot do it in plain SQL. SQL is well for set
operations. You can use plpgsql and SRF function.


-- table1 and table2 have to have same structure
CREATE OR REPLACE FUNCTION output_tab(date)
RETURNS SETOF table1 AS $$ DECLARE t1 table1; t2 table2;
BEGIN IF $1 = 'xxxx' THEN   FOR t1 IN SELECT * FROM table1 LOOP      RETURN NEXT t1;   END LOOP; ELSE   FOR t2 IN
SELECT* FROM table1 LOOP      RETURN NEXT t2;   END LOOP; END IF;RETURN;
 
END;
$$ LANGUAGE plpgsql;

and then
SELECT * FROM output_tab('xxxxx');

Regards
Pavel Stehule


2007/7/12, Ashish Karalkar <ashish.karalkar@info-spectrum.com>:
>
>
> Hello all,
>
>
> I want to select data from two diffrent table based on third tables column
> somthing like:
>
>
> select case when  t3.date='xxxx' then
>                     select * from table1
>
> else
>                     select * from table 2
>
>  from table3  t3             where t3.date='xxxxx'
>
>
> Problem is that I have to do it in Plain SQL.
>
> Is there a anyway.
>
> Thanks in Advance
>
> With egards
> Ashish....
>


pgsql-sql by date:

Previous
From: "Ashish Karalkar"
Date:
Subject: Using case or if to return multiple rows
Next
From: Ragnar
Date:
Subject: Re: Using case or if to return multiple rows