Re: any, anyelement, and anyarray - Mailing list pgsql-hackers

From Tom Lane
Subject Re: any, anyelement, and anyarray
Date
Msg-id 23824.1147441581@sss.pgh.pa.us
Whole thread Raw
In response to any, anyelement, and anyarray  (Thomas Hallgren <thomas@tada.se>)
Responses Re: any, anyelement, and anyarray
List pgsql-hackers
Thomas Hallgren <thomas@tada.se> writes:
> - Why does PostgreSQL declare three different generic types? Isn't one 
> enough? ISTM it would be far simpler to use constructs like 'any' and 
> 'any[]' but neither of them are permitted.

"any" isn't the same as "anyelement", because it doesn't have the
property of constraining different argument positions to be the same
type.  For instance, compare(any,any) and compare(anyelement,anyelement)
would accept different sets of input types.

There's some historical background to this, having to do with the fact
that "any" existed first.  Possibly we wouldn't have bothered with "any"
if all had been invented at the same time.  But I feel no pressure to
remove "any".

> - Why isn't the 'anyarray' declared as an array using the elemenent type 
> 'anyelement' in pg_type?

Because it's a pseudotype, not a type.

> - Why can't I write 'anyelement[]'. Shouldn't that be the same thing as 
> 'anyarray'?

No, you're confusing these with actual datatypes.  They are pseudotypes,
which means they're only allowed as function argument/result type
placeholders.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Jaime Casanova"
Date:
Subject: Re: BEGIN inside transaction should be an error
Next
From: Thomas Hallgren
Date:
Subject: Re: any, anyelement, and anyarray