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 <[EMAIL PROTECTED]>:


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....


---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

               http://www.postgresql.org/about/donate

Reply via email to