Re: any, anyelement, and anyarray

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Hallgren <thomas(at)tada(dot)se>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: any, anyelement, and anyarray
Date: 2006-05-12 15:06:42
Message-ID: 24514.1147446402@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thomas Hallgren <thomas(at)tada(dot)se> writes:
> I've been trying to use "any" with no luck. How do I declare a function
> that takes an "any" as a parameter?

ANY is a reserved word, so to use it as a type name you need quotes:

regression=# create function foo("any") returns int as '' language sql;
ERROR: SQL functions cannot have arguments of type "any"

(This may be another reason why we went for "anyelement" ...)

> I realize that it would be trickier to return an "any" since the
> expected return type must somehow be derived from the context where the
> function was called.

You really can't use "any" as a function result type; it's not sensible
because there's no way to infer an actual type. There are functions for
which an "any" argument type is sensible, eg count(*), but I don't see
a use for this pseudotype as a result type.

> Wouldn't it be a good idea to let the SQL parser recognize the
> anyelement[] construct as a synonym for anyarray?

[ shrug... ] Can't get excited about it. It'd complicate and confuse
the documentation, as well as the code, for zero functional improvement.
I also have a gut feeling that this is really wrong anyhow. anyarray
isn't an array, it's a placeholder.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Florian Weimer 2006-05-12 16:16:11 Re: Bug in signal handler
Previous Message Mark Campbell 2006-05-12 15:05:09 Re: Compiling on 8.1.3 on Openserver 5.05