From: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | "Ashish Karalkar" <ashish(dot)karalkar(at)info-spectrum(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Using case or if to return multiple rows |
Date: | 2007-07-12 07:09:04 |
Message-ID: | 162867790707120009i7b63994l8df60afd6b9a66f9@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(dot)karalkar(at)info-spectrum(dot)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....
>
From | Date | Subject | |
---|---|---|---|
Next Message | Ragnar | 2007-07-12 09:52:08 | Re: Using case or if to return multiple rows |
Previous Message | Ashish Karalkar | 2007-07-12 06:45:24 | Using case or if to return multiple rows |