X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8C945D1B189 for ; Wed, 2 Jun 2004 11:52:52 -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 64605-04 for ; Wed, 2 Jun 2004 14:52:55 +0000 (GMT) Received: from web13906.mail.yahoo.com (web13906.mail.yahoo.com [216.136.175.69]) by svr1.postgresql.org (Postfix) with SMTP id C9BE9D1CE22 for ; Wed, 2 Jun 2004 11:52:49 -0300 (ADT) Message-ID: <20040602145254.44625.qmail@web13906.mail.yahoo.com> Received: from [80.67.100.162] by web13906.mail.yahoo.com via HTTP; Wed, 02 Jun 2004 07:52:54 PDT Date: Wed, 2 Jun 2004 07:52:54 -0700 (PDT) From: "Riccardo G. Facchini" Subject: function with a composite type calling another function - Mission Impossible? To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200406/14 X-Sequence-Number: 17959 Hi. I'm trying to work a fairly complex set of functions that use a composite type for internal usage. This composite type should be passed to a specific function that takes care of some housekeeping actions... I haven't been able to make them work. as an example, I've generated a series of silly functions, to figure out where the problem lies: --- CREATE or replace FUNCTION public.real_to_complex(float8, float8) RETURNS complex_number AS 'declare my_real alias for $1; declare my_complex alias for $2; declare my_result complex_number; begin my_result.real := my_real; my_result.complex := my_complex; return my_result; end;' LANGUAGE 'plpgsql' VOLATILE; CREATE or replace FUNCTION public.complex_to_real(complex_number) RETURNS float8 AS 'declare my_complex alias for $1; declare my_result float; begin my_result := my_complex.real + my_complex.complex; return my_result; end;' LANGUAGE 'plpgsql' VOLATILE; CREATE or replace FUNCTION public.complex_to_complex(complex_number) RETURNS complex_number AS 'declare my_complex alias for $1; declare my_result complex_number; begin my_result.real := my_complex.real * 2; my_result.complex := my_complex.complex * 2; return my_result; end;' LANGUAGE 'plpgsql' VOLATILE; CREATE or replace FUNCTION public.really_complex(float, float) RETURNS complex_number AS 'declare my_real alias for $1; declare my_complex alias for $2; declare my_result complex_number; begin select * from real_to_complex(my_real, my_complex) into my_result; return my_result; end;' LANGUAGE 'plpgsql' VOLATILE; CREATE or replace FUNCTION public.really_really_complex(complex_number) RETURNS complex_number AS 'declare my_complex alias for $1; declare my_new_complex complex_number; declare my_result complex_number; begin select 1, 2 into my_new_complex.real, my_new_complex.complex; my_new_complex.real := my_complex.real; my_new_complex.complex := my_complex.complex; select * from complex_to_complex(my_new_complex) into my_result; return my_result; end;' LANGUAGE 'plpgsql' VOLATILE; -- the following selects work normally: --- select * from real_to_complex(1, 2); select * from complex_to_real(real_to_complex(1, 2)); select * from complex_to_complex(real_to_complex(1, 2)); select * from really_complex(1, 2); --- then, why this one doesn't work? --- select * from really_really_complex(real_to_complex(1, 2)); result: ERROR: column "my_new_complex" does not exist CONTEXT: PL/pgSQL function "really_really_complex" line 13 at select into variables -- I tried some other forms for the function really_really_complex... the answer is always the same: ---version 1 CREATE or replace FUNCTION public.really_really_complex(complex_number) RETURNS complex_number AS 'declare my_complex alias for $1; declare my_result complex_number; begin select * from complex_to_complex(my_complex) into my_result; return my_result; end;' LANGUAGE 'plpgsql' VOLATILE; --- version 2 CREATE or replace FUNCTION public.really_really_complex(complex_number) RETURNS complex_number AS 'declare my_complex alias for $1; declare my_result complex_number; begin my_result := complex_to_complex(my_complex); return my_result; end;' LANGUAGE 'plpgsql' VOLATILE; -- any suggestion/idea? what am I doing wrong? ===== Riccardo G. Facchini