Re: BUG #14854: daterange[] is an anyarray or anyrange?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: balazs(at)obiserver(dot)hu
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14854: daterange[] is an anyarray or anyrange?
Date: 2017-10-13 20:24:36
Message-ID: CAKFQuwatCNQcFg7hkHzNNtn1So316U2M-ut=0qRue9mvY6CGdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Oct 13, 2017 at 12:45 PM, <balazs(at)obiserver(dot)hu> wrote:

> The following bug has been logged on the website:
>
> Bug reference: 14854
> Logged by: Balazs Szilfai
> Email address: balazs(at)obiserver(dot)hu
> PostgreSQL version: 9.6.5
> Operating system: Debian Linux
> Description:
>
> I can't create function with param to accept a pseudo-type to daterange and
> daterange[] (array of daterange).
>
> I tried:
>
> CREATE FUNCTION range_overlap_array_any(anyrange, anyarray) RETURNS
> boolean
> AS $$SELECT false;$$ LANGUAGE sql IMMUTABLE STRICT;
>
> ​​
> CREATE FUNCTION range_overlap_array_any(anyrange, anyrange) RETURNS
> boolean
> AS $$SELECT false;$$ LANGUAGE sql IMMUTABLE STRICT;
>
> My queries and the error messages:
>
> SELECT range_overlap_array_any(daterange('2017-01-01', '2017-04-01'),
> array[daterange('2016-12-10', '2016-12-11')]);
>
> ERROR: function range_overlap_array_any(daterange, daterange[]) does not
> exist
>
>
> SELECT range_overlap_array_any(daterange('2017-01-01', '2017-04-01'),
> array['x'::text]);
>
> ERROR: function range_overlap_array_any(daterange, text[]) does not exist

> What's the mistake? Or did I break something?
>

​When a pseudo-type is used in a function parameter specification the
system enforces the constraint that the same "base" type is used for all
arguments during function invocation.

https://www.postgresql.org/docs/10/static/extend-type-system.html#extend-types-polymorphic

"Each position (either argument or return value) declared as anyelement is
allowed to have any specific actual data type, but in any given call they
must all be the same actual type. [...]" - the rest of that paragraph
basically explains with many words that which I summarize above but without
the concept of "base type" to ease comprehension.

In this case "date" is your base type so the valid combination of arguments
is
(daterange, date[])​

Your first invocation (daterange, daterange[]) works if you define your
function as "(anyelement, anyarray)"; thus making "daterange" your base
type when invoked that way.

The invocation (daterange, text[]) is not a valid combination for any pure
pseudo-argument function.

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Szilfai Balázs 2017-10-13 20:42:27 Re: BUG #14854: daterange[] is an anyarray or anyrange?
Previous Message balazs 2017-10-13 19:45:21 BUG #14854: daterange[] is an anyarray or anyrange?