PL/PGSql function within a view definition

From: Keith Haugh <kmhaugh001(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: PL/PGSql function within a view definition
Date: 2008-02-15 21:48:14
Message-ID: 623563.66234.qm@web35105.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Due to limitations (perceived or real) within my client application I am trying to return a complex dataset which I am assembling using an expensive PL/PGSql function which I would like to wrap in a writeable view.
I have written the function as both a row-level function which returns a ROWTYPE and as a table level function which returns a SETOF ROWTYPES. In both cases I have encountered issues. Please keep in mind that my end goal is to create a writeable view that my client app will treat as a simple table.
OPTION ONE - ROWTYPE
--this works correctly.
Select my_func(1);
--and this works correctly
Select my_table.a, my_func(my_table.a)
Where my_table.a in (1,2,3);
--works great.
--however when i create the following view and use the following query...
Create view my_view as select my_table.a as a, my_func(my_table.a) from my_table;
Select * from my_view where a in (1,2,3);
--the function appears to be run on each row of my_table which is not tolerable due to the size of my_table and the cost of my_func.
Any suggestions on how to force the selection of my_table records prior to executing the function?
OPTION TWO – SETOF ROWTYPE
--this works correctly.
Select * from my_func2(1);
--however
Select * from my_table, my_func(my_table.a) where my_table.a in (1,2,3);
--appears to be an illegal construct within postgres which prevents me from creating the following view.
Create view my_view as select a, b.* from my_table, my_func(my_table.a) as b;
--to be used in the following manner
Select * from my_view where a in (1,2,3);
Any suggestions on either of these two potential solutions or suggestions as to other methods are greatly appreciated.

---------------------------------
Never miss a thing. Make Yahoo your homepage.

Browse pgsql-general by date

  From Date Subject
Next Message Jozsef Szalay 2008-02-15 21:54:28 pg_restore, search_path and operator class
Previous Message Greg Smith 2008-02-15 21:36:57 Re: PG quitting sporadically!!