Oddities with ANYARRAY

From: Decibel! <decibel(at)decibel(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Oddities with ANYARRAY
Date: 2007-08-01 00:59:46
Message-ID: 20070801005945.GD25704@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

David Fetter and I were just looking at something on IRC...

decibel=# select most_common_vals[1] from pg_stats where tablename='pg_depend' and attname='classid';
ERROR: cannot subscript type anyarray because it is not an array
decibel=# select most_common_freqs[1] from pg_stats where tablename='pg_depend' and attname='classid';
most_common_freqs
-------------------
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=# 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=# select array_to_set(most_common_vals) from pg_stats where tablename='pg_depend' and attname='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=# select array_to_set(most_common_freqs) from pg_stats where tablename='pg_depend' and attname='classid';
array_to_set
--------------
0.566
0.235667
0.126333
0.0343333
0.02
0.0163333
0.000666667
0.000666667
(8 rows)

decibel=#

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...
--
Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2007-08-01 01:59:01 Re: Oddities with ANYARRAY
Previous Message Joseph S 2007-07-31 22:31:07 Re: BUG #3500: Horrible performance when wrong type is set in prepared statement