Re: [PATCH] Generic type subscription
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>,
Artur Zakirov <a.zakirov@postgrespro.ru>,
Aleksander Alekseev <a.alekseev@postgrespro.ru>,
PostgreSQL-development <pgsql-hackers@postgresql.org>,
Victor Wagner <vitus@wagner.pp.ru>,
Haribabu Kommi <kommi.haribabu@gmail.com>
Date: 2017-01-26T18:38:53Z
Lists: pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes: > On Mon, Jan 23, 2017 at 2:07 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote: >> Can we arrange to do that differently? I'd prefer something in which the >> argument and result types are visibly connected to the actual datatypes >> at hand, for instance >> array_subscript(anyarray, internal) returns anyelement >> array_assign(anyarray, internal, anyelement) returns anyarray > What about having no internal arguments here at all? Like if you want > to support foo[4] define a subscript function that takes (mytype, int) > and returns whatever. You might have to allow for multiple > subscripting functions with different argument types for this to > really work, though. Yeah, the problem is if you're trying to support the full generality of the array slice syntax, it gets kind of painful to shoehorn that into simple SQL types. Consider array[1][2:3][4:] or something like that. We could say that extensions only have access to the basic non-slice notation, but I'm sure someone would be unhappy with that --- and even then, you don't really want to define six functions to deal with six possible numbers of subscripts. Another issue is that, if someone is trying to use this facility to define array semantics that are less screwball than what Berkeley bequeathed us, they might not be happy with the idea that a single function "array_subscript(anyarray, internal) returns anyelement" is what determines the result type of a subscripting operation. It might be for example that you need to look at the subscripted object, as well as the number of subscripts, before you know whether the result is an element or a lower-dimension array. So I'd really prefer that the functionality involve a parser callout, and that would certainly need "internal" argument(s). Given that it's a parser callout, what the signatures of the runtime function(s) are is really not our problem; the callout can construct any darn expression tree it pleases. There would only be some subset of that space that ruleutils.c would know how to print as a subscripting construct, but many people might be happy with the results reverse-listing as a regular function or operator call. regards, tom lane
Commits
-
Throw error when assigning jsonb scalar instead of a composite object
- aa6e46daf530 14.0 landed
-
Filling array gaps during jsonb subscripting
- 81fcc72e6622 14.0 landed
-
Implementation of subscripting for jsonb
- 676887a3b0b8 14.0 landed
-
Support subscripting of arbitrary types, not only arrays.
- c7aba7c14efd 14.0 landed
-
Remove obsoleted code relating to targetlist SRF evaluation.
- ea15e18677fc 10.0 cited
-
Include <sys/select.h> where needed
- 51c3e9fade76 10.0 cited