Re: Using case or if to return multiple rows

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: Using case or if to return multiple rows
Дата
Msg-id 162867790707120009i7b63994l8df60afd6b9a66f9@mail.gmail.com
обсуждение исходный текст
Ответ на Using case or if to return multiple rows  ("Ashish Karalkar" <ashish.karalkar@info-spectrum.com>)
Список 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 по дате отправления:

Предыдущее
От: "Ashish Karalkar"
Дата:
Сообщение: Using case or if to return multiple rows
Следующее
От: Ragnar
Дата:
Сообщение: Re: Using case or if to return multiple rows