Обсуждение: using arrays as variable, not as field
I read the doc on http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=arrays.h tml These doc say you can use array_dims to get the dimension of an array. But when I try to do some this select array_dims('{1,2,3,4,5}'); I get this message: ERROR: Cannot accept a constant of type ANYARRAY I see several examples on "field" arrays, but I need to use a variable with array type inside pl/pgsql (not inside a table), and I need to know the length of this array. My instalation is 7.3.1. Anybody have a tip about that? Thanks in advance! -- Fernando O. Papa DBA
"Fernando Papa" <fpapa@claxson.com> writes:
> These doc say you can use array_dims to get the dimension of an array.
> But when I try to do some this
> select array_dims('{1,2,3,4,5}');
> I get this message:
> ERROR: Cannot accept a constant of type ANYARRAY
That's not an array, it's just an untyped string. This works:
regression=# select array_dims('{1,2,3,4,5}'::int[]);
array_dims
------------
[1:5]
(1 row)
regards, tom lane
Ooops... thanks a lot Tom!!!
Maybe I need to read againt some chapters...
--
Fernando O. Papa
DBA
> -----Mensaje original-----
> De: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Enviado el: jueves, 20 de marzo de 2003 13:57
> Para: Fernando Papa
> CC: pgsql-general
> Asunto: Re: [GENERAL] using arrays as variable, not as field
>
>
> "Fernando Papa" <fpapa@claxson.com> writes:
> > These doc say you can use array_dims to get the dimension
> of an array.
> > But when I try to do some this select array_dims('{1,2,3,4,5}');
> > I get this message:
> > ERROR: Cannot accept a constant of type ANYARRAY
>
> That's not an array, it's just an untyped string. This works:
>
> regression=# select array_dims('{1,2,3,4,5}'::int[]); array_dims
> ------------
> [1:5]
> (1 row)
>
>
> regards, tom lane
>