Re: [HACKERS] Missing array support - Mailing list pgsql-patches

From Joe Conway
Subject Re: [HACKERS] Missing array support
Date
Msg-id 3F0095C0.3010109@joeconway.com
Whole thread Raw
In response to Re: [HACKERS] Missing array support  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Missing array support
List pgsql-patches
Tom Lane wrote:
> Joe Conway <mail@joeconway.com> writes:
>
> +  * The rules for this resolution are as follows:
> +  * 1) if the context type is polymorphic, punt and return type_to_resolve
> +  *    unchanged
> +  * 2) if type_to_resolve is ANYARRAY (polymorphic), then return context_type
> +  *    if it is already an array type, or get its array type if not
> +  * 3) if type_to_resolve is ANYELEMENT (polymorphic), then return context_type
> +  *    if it is already an elemental type, or get its element type if not
> +  * 4) if type_to_resolve is non-polymorphic, return it unchanged
> +  */
> + Oid
> + resolve_type(Oid type_to_resolve, Oid context_type)
>
> This seems wrong.  ANYELEMENT doesn't imply conversion from array to
> element type.  I don't think you're giving resolve_type nearly enough
> context to produce a correct answer.

And the function isn't trying to do that. If I have an ANYELEMENT I'm
trying to resolve, and the context type is a scalar type, it uses that.
If the context type is array, then it uses the array's element type.


> You're not providing enough info to resolve_type to let it handle all
> four cases correctly.  In any case, this procedure seems exceedingly
> specific to the problem of resolving aggregate internal types.  I doubt
> it should be in parse_type at all, and it certainly shouldn't have a
> name as generic as resolve_type.
>

No, resolve_type() is not at all specific to polymorphic aggregates. It
implements the rules of polymorphism that we previously agreed to,
namely that an ANYARRAY can be resolved by knowing any of these data
types at the time of function call:

1) the actual call type at the same position (i.e. argument number or
    return type) as the ANYARRAY you're trying to resolve

2) the actual call type at a different position from the ANYARRAY you're
    trying to resolve, as long as the declared type at that position is
    either ANYARRAY or ANYELEMENT.

- If type_to_resolve is non-polymorphic, we have nothing in need of
resolution.

- If context_type is polymorphic, we have no context with which to do
resolution.

- If type_to_resolve is polymorphic (ANYARRAY or ANYELEMENT), and
context_type is not, resolve_type() picks the appropriate type based on
whether we need an array or not, and whether we've been given an array
or not as context.

Did you find a specific case where this falls down?

Joe



pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] Missing array support
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Missing array support