Re: pgsql: Add more SQL/JSON constructor functions

2024-09-06 Thread Amit Langote
On Fri, Sep 6, 2024 at 1:34 PM Amit Langote wrote: > On Fri, Sep 6, 2024 at 12:07 PM Amit Langote wrote: > > On Thu, Sep 5, 2024 at 9:58 PM Amit Langote wr > > Pushed. > > Reverted 0002-0004 from both master and REL_17_STABLE due to BF failures. > > 0002-0003 are easily fixed by changing the new

Re: pgsql: Add more SQL/JSON constructor functions

2024-09-05 Thread Amit Langote
On Fri, Sep 6, 2024 at 12:07 PM Amit Langote wrote: > On Thu, Sep 5, 2024 at 9:58 PM Amit Langote wrote: > > On Tue, Sep 3, 2024 at 6:05 PM jian he wrote: > > > On Mon, Sep 2, 2024 at 4:18 PM Amit Langote > > > wrote: > > > v2-0001 looks good to me. > > > +-- Test JSON_TABLE() column deparsing

Re: pgsql: Add more SQL/JSON constructor functions

2024-09-05 Thread Amit Langote
On Thu, Sep 5, 2024 at 9:58 PM Amit Langote wrote: > On Tue, Sep 3, 2024 at 6:05 PM jian he wrote: > > On Mon, Sep 2, 2024 at 4:18 PM Amit Langote wrote: > > v2-0001 looks good to me. > > +-- Test JSON_TABLE() column deparsing -- don't emit default ON ERROR / > > EMPTY > > +-- behavior > > +EXP

Re: pgsql: Add more SQL/JSON constructor functions

2024-09-05 Thread Amit Langote
Hi, On Tue, Sep 3, 2024 at 6:05 PM jian he wrote: > On Mon, Sep 2, 2024 at 4:18 PM Amit Langote wrote: > v2-0001 looks good to me. > +-- Test JSON_TABLE() column deparsing -- don't emit default ON ERROR / EMPTY > +-- behavior > +EXPLAIN VERBOSE SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text

Re: pgsql: Add more SQL/JSON constructor functions

2024-09-03 Thread jian he
On Mon, Sep 2, 2024 at 4:18 PM Amit Langote wrote: > > > See 0001. > > > > > > See 0002. > > > > I'm also attaching 0003 to fix a minor annoyance that JSON_TABLE() > > columns' default ON ERROR, ON EMPTY behaviors are unnecessarily > > emitted in the deparsed output when the top-level ON ERROR be

Re: pgsql: Add more SQL/JSON constructor functions

2024-09-02 Thread Amit Langote
On Fri, Aug 30, 2024 at 4:32 PM Amit Langote wrote: > On Thu, Aug 22, 2024 at 12:44 PM Amit Langote wrote: > > On Thu, Aug 22, 2024 at 11:02 jian he wrote: > >> On Tue, Jul 30, 2024 at 12:59 PM Amit Langote > >> wrote: > >> > On Fri, Jul 26, 2024 at 11:19 PM jian he > >> > wrote: > >> > > {

Re: pgsql: Add more SQL/JSON constructor functions

2024-08-30 Thread Amit Langote
On Thu, Aug 22, 2024 at 12:44 PM Amit Langote wrote: > On Thu, Aug 22, 2024 at 11:02 jian he wrote: >> On Tue, Jul 30, 2024 at 12:59 PM Amit Langote >> wrote: >> > On Fri, Jul 26, 2024 at 11:19 PM jian he >> > wrote: >> > > { >> > > ... >> > > /* >> > > * For expression nodes that su

Re: pgsql: Add more SQL/JSON constructor functions

2024-08-21 Thread Amit Langote
On Thu, Aug 22, 2024 at 11:02 jian he wrote: > On Tue, Jul 30, 2024 at 12:59 PM Amit Langote > wrote: > > > > Hi, > > > > On Fri, Jul 26, 2024 at 11:19 PM jian he > wrote: > > > On Fri, Jul 26, 2024 at 4:53 PM Amit Langote > wrote: > > > > > > > > > > > > Pushed 0003-0005 ahead of 0001-0002.

Re: pgsql: Add more SQL/JSON constructor functions

2024-08-21 Thread jian he
On Tue, Jul 30, 2024 at 12:59 PM Amit Langote wrote: > > Hi, > > On Fri, Jul 26, 2024 at 11:19 PM jian he wrote: > > On Fri, Jul 26, 2024 at 4:53 PM Amit Langote > > wrote: > > > > > > > > > Pushed 0003-0005 ahead of 0001-0002. Will try to push them over the > > > weekend. Rebased for now. >

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-29 Thread Amit Langote
Hi, On Fri, Jul 26, 2024 at 11:19 PM jian he wrote: > On Fri, Jul 26, 2024 at 4:53 PM Amit Langote wrote: > > > > > > Pushed 0003-0005 ahead of 0001-0002. Will try to push them over the > > weekend. Rebased for now. Pushed them now. > { > ... > /* > * For expression nodes that suppo

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-26 Thread jian he
On Fri, Jul 26, 2024 at 4:53 PM Amit Langote wrote: > > > Pushed 0003-0005 ahead of 0001-0002. Will try to push them over the > weekend. Rebased for now. { ... /* * For expression nodes that support soft errors. Should be set to NULL * before calling ExecInitExprRec() if the call

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-26 Thread Amit Langote
On Fri, Jul 26, 2024 at 11:12 AM Amit Langote wrote: > On Thu, Jul 25, 2024 at 11:16 PM Amit Langote wrote: > > On Wed, Jul 24, 2024 at 3:25 PM jian he wrote: > > > 2. domain over jsonb should fail just like domain over other types? > > > RETURNING djs keep quotes DEFAULT '"11"' ON empty > > > s

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-25 Thread Amit Langote
On Thu, Jul 25, 2024 at 11:16 PM Amit Langote wrote: > On Wed, Jul 24, 2024 at 3:25 PM jian he wrote: > > 2. domain over jsonb should fail just like domain over other types? > > RETURNING djs keep quotes DEFAULT '"11"' ON empty > > should fail as > > ERROR: could not coerce ON EMPTY expression (

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-25 Thread Amit Langote
On Wed, Jul 24, 2024 at 3:25 PM jian he wrote: > transformJsonFuncExpr we have: > case JSON_QUERY_OP: > if (jsexpr->returning->typid != JSONBOID || jsexpr->omit_quotes) > jsexpr->use_json_coercion = true; > > case JSON_VALUE_OP: > if (jsexpr-

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-24 Thread jian he
drop domain if exists djs; create domain djs as jsonb check ( value <> '"11"' ); SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING djs keep quotes DEFAULT '"11"' ON empty); SELECT JSON_QUERY(jsonb '"aaa"', '$.a' RETURNING djs omit quotes DEFAULT '"11"' ON empty); SELECT JSON_QUERY(jsonb '"11"', '$'

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-23 Thread jian he
On Tue, Jul 23, 2024 at 8:52 PM Amit Langote wrote: > > In the attached patch, I've also taken care of the problem mentioned > in your latest email -- the solution I've chosen is not to produce the > error when ERROR ON ERROR is specified but to use runtime coercion > also for the jsonb type or an

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-23 Thread Amit Langote
On Tue, Jul 23, 2024 at 11:45 AM jian he wrote: > On Mon, Jul 22, 2024 at 4:46 PM Amit Langote wrote: > > > > On Thu, Jul 18, 2024 at 3:04 PM jian he wrote: > > > we still have problem in transformJsonBehavior > > > > > > currently transformJsonBehavior: > > > SELECT JSON_VALUE(jsonb '1234', '$'

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-23 Thread jian he
While reviewing the patch, I found some inconsistency on json_table EXISTS. --tested based on your patch and master. src4=# SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a jsonb EXISTS PATH '$')); ERROR: cannot cast behavior expression of type boolean to jsonb src4=# SELECT * FROM JSON_TABLE

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-22 Thread jian he
On Mon, Jul 22, 2024 at 4:46 PM Amit Langote wrote: > > On Thu, Jul 18, 2024 at 3:04 PM jian he wrote: > > we still have problem in transformJsonBehavior > > > > currently transformJsonBehavior: > > SELECT JSON_VALUE(jsonb '1234', '$' RETURNING bit(3) DEFAULT 010111 ON > > ERROR); > > ERROR: c

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-22 Thread Amit Langote
On Thu, Jul 18, 2024 at 3:04 PM jian he wrote: > we still have problem in transformJsonBehavior > > currently transformJsonBehavior: > SELECT JSON_VALUE(jsonb '1234', '$' RETURNING bit(3) DEFAULT 010111 ON > ERROR); > ERROR: cannot cast behavior expression of type text to bit > LINE 1: ...VALUE

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-17 Thread jian he
we still have problem in transformJsonBehavior currently transformJsonBehavior: SELECT JSON_VALUE(jsonb '1234', '$' RETURNING bit(3) DEFAULT 010111 ON ERROR); ERROR: cannot cast behavior expression of type text to bit LINE 1: ...VALUE(jsonb '1234', '$' RETURNING bit(3) DEFAULT 010111 ON ... he

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-17 Thread Amit Langote
On Tue, Jul 2, 2024 at 5:03 PM Amit Langote wrote: > On Tue, Jul 2, 2024 at 3:19 PM jian he wrote: > > On Mon, Jul 1, 2024 at 6:45 PM Amit Langote wrote: > > > > > > On Sun, Jun 30, 2024 at 3:56 AM Tom Lane wrote: > > > > Alvaro Herrera writes: > > > > >> +/* > > > > >> + * For domains

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-02 Thread Amit Langote
On Tue, Jul 2, 2024 at 3:19 PM jian he wrote: > On Mon, Jul 1, 2024 at 6:45 PM Amit Langote wrote: > > > > On Sun, Jun 30, 2024 at 3:56 AM Tom Lane wrote: > > > Alvaro Herrera writes: > > > >> +/* > > > >> + * For domains, consider the base type's typmod to decide whether > > > >> to s

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-01 Thread jian he
On Mon, Jul 1, 2024 at 6:45 PM Amit Langote wrote: > > On Sun, Jun 30, 2024 at 3:56 AM Tom Lane wrote: > > Alvaro Herrera writes: > > >> +/* > > >> + * For domains, consider the base type's typmod to decide whether > > >> to setup > > >> + * an implicit or explicit cast. > > >> +

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-01 Thread Amit Langote
On Sun, Jun 30, 2024 at 3:56 AM Tom Lane wrote: > Alvaro Herrera writes: > >> +/* > >> + * For domains, consider the base type's typmod to decide whether to > >> setup > >> + * an implicit or explicit cast. > >> + */ > >> +if (get_typtype(returning->typid) == TYPTYPE_DOMAIN)

Re: pgsql: Add more SQL/JSON constructor functions

2024-07-01 Thread jian he
On Sun, Jun 30, 2024 at 2:24 AM Alvaro Herrera wrote: > > TBH I'm not super clear on why we decide on explicit or implicit cast > based on presence of a typmod. Why isn't it better to always use an > implicit one? > I am using an example to explain it. SELECT JSON_SERIALIZE(JSON('{ "a" : 1 } '))

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-29 Thread Tom Lane
Alvaro Herrera writes: >> +/* >> + * For domains, consider the base type's typmod to decide whether to >> setup >> + * an implicit or explicit cast. >> + */ >> +if (get_typtype(returning->typid) == TYPTYPE_DOMAIN) >> +(void) getBaseTypeAndTypmod(returning->typid, &

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-29 Thread Alvaro Herrera
> diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c > index 233b7b1cc9..df766cdec1 100644 > --- a/src/backend/parser/parse_expr.c > +++ b/src/backend/parser/parse_expr.c > @@ -3583,6 +3583,7 @@ coerceJsonFuncExpr(ParseState *pstate, Node *expr, > Node *res;

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-28 Thread Amit Langote
On Fri, Jun 28, 2024 at 3:14 PM jian he wrote: > On Thu, Jun 27, 2024 at 7:48 PM Amit Langote wrote: > > > > > > I've attempted that in the attached 0001, which removes > > > JsonExpr.coercion_expr and a bunch of code around it. > > > > > > 0002 is now the original patch minus the changes to make

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-27 Thread jian he
On Thu, Jun 27, 2024 at 7:48 PM Amit Langote wrote: > > > > I've attempted that in the attached 0001, which removes > > JsonExpr.coercion_expr and a bunch of code around it. > > > > 0002 is now the original patch minus the changes to make > > JSON_EXISTS(), JSON_QUERY(), and JSON_VALUE() behave as

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-27 Thread Amit Langote
On Thu, Jun 27, 2024 at 6:57 PM Amit Langote wrote: > On Wed, Jun 26, 2024 at 11:46 PM jian he wrote: > > On Wed, Jun 26, 2024 at 8:39 PM Amit Langote > > wrote: > > > > > > > > > > > The RETURNING variant giving an error is what the standard asks us to > > > > do apparently. I read Tom's last

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-27 Thread Amit Langote
Hi, On Wed, Jun 26, 2024 at 11:46 PM jian he wrote: > On Wed, Jun 26, 2024 at 8:39 PM Amit Langote wrote: > > > > > > > > The RETURNING variant giving an error is what the standard asks us to > > > do apparently. I read Tom's last message on this thread as agreeing > > > to that, even though he

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-26 Thread jian he
hi. I have assembled a list of simple examples, some works (for comparison sake), most not work as intended. CREATE DOMAIN queryfuncs_char2 AS char(2) CHECK (VALUE NOT IN ('12')); CREATE DOMAIN queryfuncs_d_interval AS interval(2) CHECK (VALUE is not null); SELECT JSON_VALUE(jsonb '111', '$' RETU

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-26 Thread jian he
On Wed, Jun 26, 2024 at 8:39 PM Amit Langote wrote: > > > > > The RETURNING variant giving an error is what the standard asks us to > > do apparently. I read Tom's last message on this thread as agreeing > > to that, even though hesitantly. He can correct me if I got that > > wrong. > > > > > yo

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-26 Thread Amit Langote
On Fri, Jun 21, 2024 at 10:48 PM Amit Langote wrote: > On Fri, Jun 21, 2024 at 4:05 PM jian he wrote: > > hi. > > i am a little confused. > > > > here[1] tom says: > > > Yeah, I too think this is a cast, and truncation is the spec-defined > > > behavior for casting to varchar with a specific leng

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-21 Thread Amit Langote
Hi, Thanks for taking a look. On Fri, Jun 21, 2024 at 4:05 PM jian he wrote: > On Tue, Jun 18, 2024 at 5:02 PM Amit Langote wrote: > > On Tue, Jun 4, 2024 at 7:03 PM Amit Langote wrote: > > > On Tue, Jun 4, 2024 at 2:20 AM Tom Lane wrote: > > > > Peter Eisentraut writes: > > > > > On 02.06.2

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-21 Thread jian he
On Tue, Jun 18, 2024 at 5:02 PM Amit Langote wrote: > > On Tue, Jun 4, 2024 at 7:03 PM Amit Langote wrote: > > On Tue, Jun 4, 2024 at 2:20 AM Tom Lane wrote: > > > Peter Eisentraut writes: > > > > On 02.06.24 21:46, Tom Lane wrote: > > > >> If you don't > > > >> like our current behavior, then

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-18 Thread Amit Langote
On Tue, Jun 4, 2024 at 7:03 PM Amit Langote wrote: > On Tue, Jun 4, 2024 at 2:20 AM Tom Lane wrote: > > Peter Eisentraut writes: > > > On 02.06.24 21:46, Tom Lane wrote: > > >> If you don't > > >> like our current behavior, then either you have to say that RETURNING > > >> with a length-limited

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-04 Thread Amit Langote
On Tue, Jun 4, 2024 at 2:20 AM Tom Lane wrote: > Peter Eisentraut writes: > > On 02.06.24 21:46, Tom Lane wrote: > >> If you don't > >> like our current behavior, then either you have to say that RETURNING > >> with a length-limited target type is illegal (which is problematic > >> for the spec,

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-03 Thread Tom Lane
Peter Eisentraut writes: > On 02.06.24 21:46, Tom Lane wrote: >> If you don't >> like our current behavior, then either you have to say that RETURNING >> with a length-limited target type is illegal (which is problematic >> for the spec, since they have no such type) or that the cast behaves >> li

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-03 Thread Peter Eisentraut
On 02.06.24 21:46, Tom Lane wrote: If you don't like our current behavior, then either you have to say that RETURNING with a length-limited target type is illegal (which is problematic for the spec, since they have no such type) or that the cast behaves like an implicit cast, with errors for over

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-02 Thread Tom Lane
Peter Eisentraut writes: > On 29.05.24 18:44, Tom Lane wrote: >> Yeah, I too think this is a cast, and truncation is the spec-defined >> behavior for casting to varchar with a specific length limit. > The SQL standard says essentially that the output of json_serialize() is > some string that whe

Re: pgsql: Add more SQL/JSON constructor functions

2024-06-02 Thread Peter Eisentraut
On 29.05.24 18:44, Tom Lane wrote: Amit Langote writes: On Mon, May 27, 2024 at 7:10 PM Alvaro Herrera wrote: On 2024-May-27, Alvaro Herrera wrote: I just noticed this behavior, which looks like a bug to me: select json_serialize('{"a":1, "a":2}' returning varchar(5)); json_serialize ───

Re: pgsql: Add more SQL/JSON constructor functions

2024-05-29 Thread Tom Lane
Amit Langote writes: > On Mon, May 27, 2024 at 7:10 PM Alvaro Herrera > wrote: >> On 2024-May-27, Alvaro Herrera wrote: >> I just noticed this behavior, which looks like a bug to me: >> >> select json_serialize('{"a":1, "a":2}' returning varchar(5)); >> json_serialize >> >> {"a

Re: pgsql: Add more SQL/JSON constructor functions

2024-05-28 Thread Amit Langote
Hi Alvaro, On Mon, May 27, 2024 at 7:10 PM Alvaro Herrera wrote: > > On 2024-May-27, Alvaro Herrera wrote: > > > > JSON_SERIALIZE() > > I just noticed this behavior, which looks like a bug to me: > > select json_serialize('{"a":1, "a":2}' returning varchar(5)); > json_serialize > ───

Re: pgsql: Add more SQL/JSON constructor functions

2024-05-28 Thread David G. Johnston
On Monday, May 27, 2024, Alvaro Herrera wrote: > On 2024-May-27, Alvaro Herrera wrote: > > > > JSON_SERIALIZE() > > I just noticed this behavior, which looks like a bug to me: > > select json_serialize('{"a":1, "a":2}' returning varchar(5)); > json_serialize > > {"a": > > I thi

Re: pgsql: Add more SQL/JSON constructor functions

2024-05-27 Thread Alvaro Herrera
On 2024-May-27, Alvaro Herrera wrote: > > JSON_SERIALIZE() I just noticed this behavior, which looks like a bug to me: select json_serialize('{"a":1, "a":2}' returning varchar(5)); json_serialize {"a": I think this function should throw an error if the destination type doesn