Oddities with ANYARRAY - Mailing list pgsql-bugs

From Decibel!
Subject Oddities with ANYARRAY
Date
Msg-id 20070801005945.GD25704@nasby.net
Whole thread Raw
Responses Re: Oddities with ANYARRAY
Re: Oddities with ANYARRAY
Re: Oddities with ANYARRAY
List pgsql-bugs
David Fetter and I were just looking at something on IRC...

decibel=3D# select most_common_vals[1] from pg_stats where tablename=3D'pg_=
depend' and attname=3D'classid';
ERROR:  cannot subscript type anyarray because it is not an array
decibel=3D# select most_common_freqs[1] from pg_stats where tablename=3D'pg=
_depend' and attname=3D'classid';
 most_common_freqs=20
-------------------
             0.566
(1 row)

ISTM you'd want to be able to reference an individual element of an
ANYARRAY... but this gets even more odd...

decibel=3D# CREATE OR REPLACE FUNCTION array_to_set(anyarray) RETURNS SETOF=
 anyelement LANGUAGE SQL AS $$
    SELECT $1[i] from generate_series(array_lower($1, 1), array_upper($1, 1=
)) i
$$;
CREATE FUNCTION
decibel=3D# select array_to_set(most_common_vals) from pg_stats where table=
name=3D'pg_depend' and attname=3D'classid';
ERROR:  argument declared "anyarray" is not an array but type anyarray

I expected that not to work, but the error is somewhat interesting...

I didn't expect the following to work:

decibel=3D# select array_to_set(most_common_freqs) from pg_stats where tabl=
ename=3D'pg_depend' and attname=3D'classid';
 array_to_set=20
--------------
        0.566
     0.235667
     0.126333
    0.0343333
         0.02
    0.0163333
  0.000666667
  0.000666667
(8 rows)

decibel=3D#=20

ISTM you should be able to call an anyarray function with an anyarray,
and that you should be able to reference individual elements of an
anyarray...
--=20
Decibel!, aka Jim Nasby                        decibel@decibel.org
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)

pgsql-bugs by date:

Previous
From: Joseph S
Date:
Subject: Re: BUG #3500: Horrible performance when wrong type is set in prepared statement
Next
From: Tom Lane
Date:
Subject: Re: Oddities with ANYARRAY