X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0A3C9DA792 for ; Thu, 20 Oct 2005 13:50:59 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55967-08 for ; Thu, 20 Oct 2005 16:50:56 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9BB0EDA7EE for ; Thu, 20 Oct 2005 13:50:56 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9KGoscc011635; Thu, 20 Oct 2005 12:50:54 -0400 (EDT) To: Kuba Ouhrabka Cc: Merlin Moncure , pgsql-performance@postgresql.org Subject: Re: cached plans in plpgsql In-reply-to: <4357C4E8.6010602@comgate.cz> References: <6EE64EF3AB31D5448D0007DD34EEB3417DD640@Herge.rcsinc.local> <4357C4E8.6010602@comgate.cz> Comments: In-reply-to Kuba Ouhrabka message dated "Thu, 20 Oct 2005 18:25:12 +0200" Date: Thu, 20 Oct 2005 12:50:54 -0400 Message-ID: <11634.1129827054@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/287 X-Sequence-Number: 15055 Kuba Ouhrabka writes: > IF Var_datos.pronargs > 0 THEN > Var_args := ''; > FOR i IN 0..Var_datos.pronargs-1 LOOP > SELECT typname::varchar INTO Var_nameArg FROM pg_type WHERE oid = Var_datos.proargtypes[i]; > Var_args := Var_args|| COALESCE(Var_datos.proargnames[i+1], '') || ' ' || Var_nameArg||', '; > END LOOP; This will not work at all; it makes far too many incorrect assumptions, like proargnames always being non-null and having subscripts that match proargtypes. (It'll mess things up completely for anything that has OUT arguments, too.) It's pretty much the hard way to form a function reference anyway --- you can just cast the function OID to regprocedure, which aside from avoiding a lot of subtle assumptions about the catalog contents, will deal with schema naming issues, something the above likewise fails at. To avoid having to reconstruct argument names/types, I'd suggest using an ALTER FUNCTION command instead of CREATE OR REPLACE FUNCTION, maybe DECLARE fullproname text := a_oid::regprocedure; ... EXECUTE 'ALTER FUNCTION ' || fullproname || ' RENAME TO ' || Var_datos.proname; regards, tom lane