Ioana Danes wrote > > If I will have to filter the tmp_Cashdrawer table then it executes the > function for the all the cash drawers and then filter out the result which > again is not efficient... Hm???? SELECT function_call(...) FROM tbl WHERE tbl.pk = ...; That should only cause function_call to execute a single time. If it is not I'd suggest providing the actual query as well as the "EXPLAIN" plan for it. It is possible that making the function "cost more" might be necessary but doubtful. You can force the table filter to be executed first by using a simple sub-select: SELECT function_call(...) FROM (SELECT * FROM tbl WHERE tbl.pk = ...) filtered_tbl; Though it is possible the planner would re-arrange this to the simple form and still cause a problem. Explain is your friend. Combine that with the "WITH" if you need to expand the results of function_call without causing it to execute multiple times - once for each column being expanded. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Function-use-in-query-tp5758051p5758159.html Sent from the PostgreSQL - general mailing list archive at Nabble.com. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general