Re: Odd behavior in functions w/ anyarray & anyelement - Mailing list pgsql-general

From David Johnston
Subject Re: Odd behavior in functions w/ anyarray & anyelement
Date
Msg-id 1378949957010-5770555.post@n5.nabble.com
Whole thread Raw
In response to Odd behavior in functions w/ anyarray & anyelement  (Joshua Burns <jdburnz@gmail.com>)
List pgsql-general
Joshua Burns wrote
> CREATE OR REPLACE FUNCTION anyel_anyar(anyelement) RETURNS anyarray AS
> $BODY$
>     BEGIN
>         RETURN $1;
>     END;
> $BODY$ LANGUAGE plpgsql;

Two possible interpretations:

1) must return an array of whatever type is supplied; this is (apparently)
the defined behavior
2) must return an array whose base type is the same as the base type of the
input

The first interpretation seems the most useful.  Your last two examples for
this function should indeed fail.

That said I am not really sure why they have to.  In theory "RETURN
anyarray", if paired with an array anyelement, could output/require an array
with one additional dimension compared to the input.  In your example you
should expect something like:

3) ARRAY[ARRAY['one','two']::text[]]::text[][]

I guess this could be considered a third interpretation....

So the bigger question is: should PostgreSQL really care?  Option #2 then
makes the fewest assumptions: the base types must match AND the output must
be some form of array.

And the biggest question is whether there are use-cases for the more
complex/flexible behavior so that someone may be enticed to implement it -
and consider the backward compatibility concerns.

Regardless, hopefully this aids your understanding.

David J.






--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Odd-behavior-in-functions-w-anyarray-anyelement-tp5770537p5770555.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: "ascot.moss@gmail.com"
Date:
Subject: fsync and wal_sync_method
Next
From: David Johnston
Date:
Subject: Re: Odd behavior in functions w/ anyarray & anyelement