create function foo(int) ... ... select ... where keycol = $1; ... looks the same as PREPARE q(int) AS select ... where keycol = $1; and you can investigate the plan for this with EXPLAIN [ANALYZE] EXECUTE q(42); Clear? It'd be nice to have more infrastructure for debugging plpgsql code, but so far no one's got round to building any :-( regards, tom lane