pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Introduce "anycompatible" family of polymorphic types.
Date: Thu, 19 Mar 2020 15:43:21 +0000
Message-ID: <E1jExKL-0008Sv-LI@gemulon.postgresql.org> (raw)

Introduce "anycompatible" family of polymorphic types.

This patch adds the pseudo-types anycompatible, anycompatiblearray,
anycompatiblenonarray, and anycompatiblerange.  They work much like
anyelement, anyarray, anynonarray, and anyrange respectively, except
that the actual input values need not match precisely in type.
Instead, if we can find a common supertype (using the same rules
as for UNION/CASE type resolution), then the parser automatically
promotes the input values to that type.  For example,
"myfunc(anycompatible, anycompatible)" can match a call with one
integer and one bigint argument, with the integer automatically
promoted to bigint.  With anyelement in the definition, the user
would have had to cast the integer explicitly.

The new types also provide a second, independent set of type variables
for function matching; thus with "myfunc(anyelement, anyelement,
anycompatible) returns anycompatible" the first two arguments are
constrained to be the same type, but the third can be some other
type, and the result has the type of the third argument.  The need
for more than one set of type variables was foreseen back when we
first invented the polymorphic types, but we never did anything
about it.

Pavel Stehule, revised a bit by me

Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/24e2885ee304cb6a94fdfc25a1a108344ed9f4f7

Modified Files
--------------
doc/src/sgml/datatype.sgml                     |  63 ++-
doc/src/sgml/extend.sgml                       | 183 ++++++++-
doc/src/sgml/plpgsql.sgml                      |  50 ++-
doc/src/sgml/xfunc.sgml                        |  57 ++-
src/backend/catalog/index.c                    |   8 +-
src/backend/catalog/pg_proc.c                  |   3 +
src/backend/commands/functioncmds.c            |   1 +
src/backend/parser/parse_coerce.c              | 527 +++++++++++++++++++++++--
src/backend/utils/adt/json.c                   |   2 +-
src/backend/utils/adt/jsonb.c                  |   2 +-
src/backend/utils/adt/pseudotypes.c            |  35 ++
src/backend/utils/fmgr/funcapi.c               | 196 ++++++++-
src/include/catalog/catversion.h               |   2 +-
src/include/catalog/pg_proc.dat                |  45 ++-
src/include/catalog/pg_type.dat                |  30 +-
src/include/catalog/pg_type.h                  |  11 +
src/pl/plpgsql/src/pl_comp.c                   |  12 +-
src/test/regress/expected/aggregates.out       |  24 ++
src/test/regress/expected/create_aggregate.out |  28 +-
src/test/regress/expected/opr_sanity.out       |  52 ++-
src/test/regress/expected/plpgsql.out          | 101 +++++
src/test/regress/expected/polymorphism.out     | 311 +++++++++++++++
src/test/regress/expected/rangefuncs.out       |  53 +++
src/test/regress/expected/rangetypes.out       |  26 ++
src/test/regress/expected/type_sanity.out      |  10 +-
src/test/regress/sql/aggregates.sql            |   4 +
src/test/regress/sql/create_aggregate.sql      |  34 +-
src/test/regress/sql/opr_sanity.sql            |  33 +-
src/test/regress/sql/plpgsql.sql               |  68 ++++
src/test/regress/sql/polymorphism.sql          | 159 ++++++++
src/test/regress/sql/rangefuncs.sql            |  21 +
src/test/regress/sql/rangetypes.sql            |  16 +
src/test/regress/sql/type_sanity.sql           |  10 +-
33 files changed, 2046 insertions(+), 131 deletions(-)



Message-ID: <E1jExKL-0008Sv-LI@gemulon.postgresql.org>
Permalink:  ../E1jExKL-0008Sv-LI@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1jExKL-0008Sv-LI@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Introduce "anycompatible" family of polymorphic types.
  In-Reply-To: <E1jExKL-0008Sv-LI@gemulon.postgresql.org>
  References: <E1jExKL-0008Sv-LI@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox