pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Riccardo G. Facchini <abief_ag_-postgresql@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: function with a composite type calling another function - Mission Impossible?
Date: Wed, 2 Jun 2004 07:52:54 -0700 (PDT)
Message-ID: <20040602145254.44625.qmail@web13906.mail.yahoo.com> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <20040602145254.44625.qmail@web13906.mail.yahoo.com>
Permalink:  ../20040602145254.44625.qmail@web13906.mail.yahoo.com/
Also on:    postgresql.org/message-id/20040602145254.44625.qmail@web13906.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: abief_ag_-postgresql@yahoo.com
  Subject: Re: function with a composite type calling another function - Mission Impossible?
  In-Reply-To: <20040602145254.44625.qmail@web13906.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox