On Thu, Oct 29, 2009 at 12:05:54PM +0200, Sim Zacks wrote: > 326/getdisplayconversionmultiplebypn(pnid) is in this query 6 times. How > many times is it evaluated? I'm pretty sure it'll evaluated multiple times. Why don't you put it into a sub-select, it'll at least save some typing. Something like: SELECT pnid, calc + case when ... then .. else ... end AS qty FROM ( SELECT pnid, 326/getdisplayconversionmultiplebypn(pnid) AS calc, ... FROM ...) x; I have a feeling that it may still get evaluated several times in certain cases, but you could put a "RAISE NOTICE" into your code to figure out. -- Sam http://samason.me.uk/ -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general