Thread: PROBLEM WITH FUNCTIONS

PROBLEM WITH FUNCTIONS

From
"Mario Alberto Soto Cordones"
Date:
Hi.

i have a problem with a function.

i create a type unidades  CREATE TYPE unidades AS (codigo numeric(3,0),                           descripcion text);

and i create a function get_unidades   CREATE FUNCTION get_unidades(int4, int4, int4, int4) RETURNS  typeof
unidades AS '
SELECT cucoduni, cudesuni
FROM cumauni
WHERE cuempuni = $1 and     cuseduni = $2 and     cucaruni = $3 and     cuasiuni= $4
; '  LANGUAGE 'sql';

and at this moment´s it´s all ok BUT when execute this function    select get_unidades(10,1,15,17)

say    "cannot display a value of type RECORD"

any idea, PLEASE HELP MY

saludos



Re: PROBLEM WITH FUNCTIONS

From
Randall Lucas
Date:
Mario,

If your function returns a record, you have to treat it like it's a
relation (table).  So you don't select it, you select from it.

Try:

select * from get_unidades(10, 1, 15, 17);

Also you may have to give it an explicit variable list such as:

select * from get_unidades(10,1,15,17) as (codigo numeric(3,0),
descripcion text);

Best,

Randall

On Monday, April 21, 2003, at 05:38 PM, Mario Alberto Soto Cordones
wrote:

> Hi.
>
> i have a problem with a function.
>
> i create a type unidades
>    CREATE TYPE unidades AS (codigo numeric(3,0),
>                             descripcion text);
>
> and i create a function get_unidades
>     CREATE FUNCTION get_unidades(int4, int4, int4, int4) RETURNS
> typeof
> unidades AS '
> SELECT cucoduni, cudesuni
> FROM cumauni
> WHERE cuempuni = $1 and
>       cuseduni = $2 and
>       cucaruni = $3 and
>       cuasiuni= $4
> ; '  LANGUAGE 'sql';
>
> and at this moment´s it´s all ok BUT when execute this function
>      select get_unidades(10,1,15,17)
>
> say
>      "cannot display a value of type RECORD"
>
> any idea, PLEASE HELP MY
>
> saludos
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>



Re: PROBLEM WITH FUNCTIONS

From
"Mario Alberto Soto Cordones"
Date:
Thank Randall

this  select * from get_unidades(10, 1, 15, 17);

work very good

thank, very much

Muchas, Muchas gracias
un gran saludo desde chile

Mario

> Mario,
>
> If your function returns a record, you have to treat it like it's a
> relation (table).  So you don't select it, you select from it.
>
> Try:
>
> select * from get_unidades(10, 1, 15, 17);
>
> Also you may have to give it an explicit variable list such as:
>
> select * from get_unidades(10,1,15,17) as (codigo numeric(3,0),
> descripcion text);
>
> Best,
>
> Randall
>
> On Monday, April 21, 2003, at 05:38 PM, Mario Alberto Soto Cordones
> wrote:
>
>> Hi.
>>
>> i have a problem with a function.
>>
>> i create a type unidades
>>    CREATE TYPE unidades AS (codigo numeric(3,0),
>>                             descripcion text);
>>
>> and i create a function get_unidades
>>     CREATE FUNCTION get_unidades(int4, int4, int4, int4) RETURNS
>> typeof
>> unidades AS '
>> SELECT cucoduni, cudesuni
>> FROM cumauni
>> WHERE cuempuni = $1 and
>>       cuseduni = $2 and
>>       cucaruni = $3 and
>>       cuasiuni= $4
>> ; '  LANGUAGE 'sql';
>>
>> and at this moment´s it´s all ok BUT when execute this function
>>      select get_unidades(10,1,15,17)
>>
>> say
>>      "cannot display a value of type RECORD"
>>
>> any idea, PLEASE HELP MY
>>
>> saludos
>>
>>
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 4: Don't 'kill -9' the postmaster
>>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


--   Mario Soto Cordones Gerente de ProyectosCompuall Ingeniería Ltda.