proposal: new polymorphic types - commontype and commontypearray

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема proposal: new polymorphic types - commontype and commontypearray
Дата
Msg-id CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
обсуждение исходный текст
Ответы Re: proposal: new polymorphic types - commontype and commontypearray  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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


Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Jeremy Finzel
Дата:
Сообщение: Re: No such file or directory in pg_replslot
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Statement-level rollback