From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | proposal: new polymorphic types - commontype and commontypearray |
Date: | 2018-12-08 20:05:16 |
Message-ID: | CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
the possibility to use polymorphic types is a specific interesting
PostgreSQL feature. The polymorphic types allows to use almost all types,
but when some type is selected, then this type is required strictly without
possibility to use some implicit casting.
So if I have a fx(anyelement, anyelement), then I can call function fx with
parameters (int, int), (numeric, numeric), but I cannot to use parameters
(int, numeric). The strict design has sense, but for few important cases is
too restrictive. We are not able to implement (with plpgsql) functions like
coalesce, greatest, least where all numeric types can be used.
Alternative solution can be based on usage "any" type. But we can work with
this type only from "C" extensions, and there is some performance
penalization due dynamic casting inside function.
Four years ago I proposed implicit casting to common type of arguments with
anyelement type.
My proposal was rejected, because it introduce compatibility issues.
Now I have a solution that doesn't break anything. With two new polymorphic
types: commontype and commontypearray we can write functions like coalesce,
greatest, ..
More, these types are independent on current polymorphic types - and can be
used with current polymorphic types together to cover some new use cases.
CREATE OR REPLACE FUNCTION fx(anyelement, commontype, anyelement,
commontype)
RETURNS commontype
or
CREATE OR REPLACE FUNCTION fx(anyelement, commontype, anyelement,
commontype)
RETURNS anyelement
and commontype and anyelement types can be really independent.
Comments, notes?
Regards
Pavel
Attachment | Content-Type | Size |
---|---|---|
commontype-poc.patch | text/x-patch | 50.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2018-12-08 20:10:27 | Re: Statement-level rollback |
Previous Message | Jeremy Finzel | 2018-12-08 19:21:38 | Re: No such file or directory in pg_replslot |