Re: transforms - Mailing list pgsql-hackers

From Chapman Flack
Subject Re: transforms
Date
Msg-id 68041730.4020603@acm.org
Whole thread Raw
In response to Re: transforms  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: transforms
List pgsql-hackers
On 04/19/25 15:03, Tom Lane wrote:
> So what are the odds that outside PLs do it correctly (for whatever
> you think "correctly" is)?  It doesn't help any that we document
> none of this.

My sense of Déjà vu turns out to be because I had a bunch of proposed
new documentation and example code for plsample in a commitfest a few
years back[0] but had to set it aside at the time. And it's becoming clear
there's even more to be nailed down than I realized at the time anyway.

> If I had my druthers I would flush every one of these special rules,
> and just say that an argument/result gets transformed if there's a
> transform matching its declared type, full stop.  You want to
> transform arrays or domains, you make a transform to match.
> This would be a lot simpler to understand and potentially more
> flexible.  But I don't know if it falls foul of the wording of
> the spec, and I concede that in some cases it'd require users
> to do more work creating those additional transforms.

I don't see right offhand that it would fall afoul of the spec.

I had also proposed in that earlier CF to change some of what our doc
says about the spec. We currently say "There is a CREATE TRANSFORM command
in the SQL standard, but it is for adapting data types to client languages"
and I don't think it's as different as that suggests. 4.9.6 clearly says
the from-sql function is invoked whenever a value "is passed to a host-
language program *or an external routine*" and the to-sql function is
invoked whenever a value "is supplied by a host-language program *or an
external routine*" (asterisks mine).

The biggest difference is our use of type internal to allow transforming
to arbitrary PL data types: the ISO to- and from-sql functions have to
interface with the external routine using predefined SQL types.

ISO does have a notion of user-defined types being subtypes or supertypes
of each other, and sections 9.31 and 9.33 on determining the applicable
from-sql or to-sql function do involve examining a type's supertypes to
find one that has a transform matching the wanted transform group name.
I don't see anything, though, about peering into array or range or domain
types.

Perhaps we could regard a domain as a subtype of its base type, but
I do not see for sure that the spec does.

I think that a transform-must-match-declared-type rule would not be
at odds with the spec.

Regards,
-Chap


[0] https://commitfest.postgresql.org/patch/3554/



pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: jsonapi: scary new warnings with LTO enabled
Next
From: Sami Imseih
Date:
Subject: Re: [BUG] temporary file usage report with extended protocol and unnamed portals