Search Postgresql Archives

Re: Instaltiating an ARRAY within a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Danny Abraham wrote:
> ===========================================
> 
> CREATE OR REPLACE FUNCTION arr( inout x varchar[] )
> AS
> $Z$
> DECLARE
>   i integer;
> BEGIN
> select ARRAY['Danny','Eissam','Moshe'] into x;
> end;
> $Z$ LANGUAGE 'plpgsql' VOLATILE;
> 
> ===========================================
> 
> CREATE OR REPLACE FUNCTION callarr()
> returns integer
> AS
> $Z$
> DECLARE
>   x varchar[6]; 
> BEGIN
> perform arr(x);
> RAISE NOTICE 'x[1]=%',x[1];
> return 0;
> end;
> $Z$ LANGUAGE 'plpgsql' VOLATILE;
> 
> ===========================================
> 
> select callarr();
> NOTICE:  x[1]=<NULL>  ??? Should have been DANNY
> 
> 
> Should it work?

Not the way you wrote it.
You are confused by output parameters which do not work the way one
might expect. They are just a simple syntax for composite return types.

CREATE FUNCTION arr(INOUT x varchar[])
is synonymous to
CREATE FUNCTION arr(x varchar[]) RETURNS varchar[]

So your example should work if you replace

PERFORM arr(x);
with
x := arr(x);

Yours,
Laurenz Albe

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
       message can get through to the mailing list cleanly


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux