Re: [HACKERS] [PATCH] Generic type subscripting - Mailing list pgsql-hackers

From Chapman Flack
Subject Re: [HACKERS] [PATCH] Generic type subscripting
Date
Msg-id 5FDBBAE4.2020501@anastigmatix.net
Whole thread Raw
In response to Re: [HACKERS] [PATCH] Generic type subscripting  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] [PATCH] Generic type subscripting
List pgsql-hackers
On 12/17/20 14:28, Tom Lane wrote:
> Pavel Stehule <pavel.stehule@gmail.com> writes:
>>   n int;
>>   v varchar;
>>   js jsonb default '{"n": 100, "v" : "Hello"};
>> BEGIN
>>   n := js['n'];
>>   v := js['v'];
> 
> If you're imagining that js['n'] and js['v'] would emit different
> datatypes, forget it.  That would require knowing at parse time
> what the structure of the json object will be at run time.

Would it be feasible to analyze that as something like an implicit
'treat as' with the type of the assignment target?

'treat as' is an operator in XML Query that's distinct from 'cast as';
'cast as foo' has ordinary cast semantics and can coerce non-foo to foo;
'treat as foo' is just a promise from the programmer: "go ahead and
statically rely on this being a foo, and give me a runtime exception
if it isn't".

It would offer a nice economy of expression.

Following that idea further, if there were such a thing as a 'treat as'
node, would the implicit generation of such a node, according to an
assignment target data type, be the kind of thing that could be accomplished
by a user function's planner-support function?

Regards,
-Chap



pgsql-hackers by date:

Previous
From: Dmitry Dolgov
Date:
Subject: Re: [HACKERS] [PATCH] Generic type subscripting
Next
From: Pavel Stehule
Date:
Subject: Re: [HACKERS] [PATCH] Generic type subscripting