Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4fc6a55

Browse files
committed
SQL/JSON: Respect OMIT QUOTES when RETURNING domains over jsonb
populate_domain() didn't take into account the omit_quotes flag passeddown to json_populate_type() by ExecEvalJsonCoercion() and that ledto incorrect behavior when the RETURNING type is a domain overjsonb. Fix that by passing the flag by adding a new functionparameter to populate_domain().Reported-by: Jian He <jian.universality@gmail.com>Discussion:https://postgr.es/m/CACJufxEo4sUjKCYtda0_qt9tazqqKPmF1cqhW9KBOUeJFqQd2g@mail.gmail.comBackpatch-through: 17
1 parent231b7d6 commit4fc6a55

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

‎src/backend/utils/adt/jsonfuncs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static void prepare_column_cache(ColumnIOData *column, Oid typid, int32 typmod,
453453
staticDatumpopulate_record_field(ColumnIOData*col,Oidtypid,int32typmod,
454454
constchar*colname,MemoryContextmcxt,Datumdefaultval,
455455
JsValue*jsv,bool*isnull,Node*escontext,
456-
boolomit_quotes);
456+
boolomit_scalar_quotes);
457457
staticRecordIOData*allocate_record_info(MemoryContextmcxt,intncolumns);
458458
staticboolJsObjectGetField(JsObject*obj,char*field,JsValue*jsv);
459459
staticvoidpopulate_recordset_record(PopulateRecordsetState*state,JsObject*obj);
@@ -470,7 +470,7 @@ static Datum populate_array(ArrayIOData *aio, const char *colname,
470470
Node*escontext);
471471
staticDatumpopulate_domain(DomainIOData*io,Oidtypid,constchar*colname,
472472
MemoryContextmcxt,JsValue*jsv,bool*isnull,
473-
Node*escontext);
473+
Node*escontext,boolomit_quotes);
474474

475475
/* functions supporting jsonb_delete, jsonb_set and jsonb_concat */
476476
staticJsonbValue*IteratorConcat(JsonbIterator**it1,JsonbIterator**it2,
@@ -3218,7 +3218,8 @@ populate_domain(DomainIOData *io,
32183218
MemoryContextmcxt,
32193219
JsValue*jsv,
32203220
bool*isnull,
3221-
Node*escontext)
3221+
Node*escontext,
3222+
boolomit_quotes)
32223223
{
32233224
Datumres;
32243225

@@ -3229,7 +3230,7 @@ populate_domain(DomainIOData *io,
32293230
res=populate_record_field(io->base_io,
32303231
io->base_typid,io->base_typmod,
32313232
colname,mcxt,PointerGetDatum(NULL),
3232-
jsv,isnull,escontext,false);
3233+
jsv,isnull,escontext,omit_quotes);
32333234
Assert(!*isnull||SOFT_ERROR_OCCURRED(escontext));
32343235
}
32353236

@@ -3461,7 +3462,7 @@ populate_record_field(ColumnIOData *col,
34613462

34623463
caseTYPECAT_DOMAIN:
34633464
returnpopulate_domain(&col->io.domain,typid,colname,mcxt,
3464-
jsv,isnull,escontext);
3465+
jsv,isnull,escontext,omit_scalar_quotes);
34653466

34663467
default:
34673468
elog(ERROR,"unrecognized type category '%c'",typcat);

‎src/test/regress/expected/sqljson_queryfuncs.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,21 @@ SELECT JSON_QUERY(jsonb'{"rec": "[1,2]"}', '$.rec' returning int4range keep quot
734734
SELECT JSON_QUERY(jsonb'{"rec": "[1,2]"}', '$.rec' returning int4range keep quotes error on error);
735735
ERROR: malformed range literal: ""[1,2]""
736736
DETAIL: Missing left parenthesis or bracket.
737+
CREATE DOMAIN qf_char_domain AS char(1);
738+
CREATE DOMAIN qf_jsonb_domain AS jsonb;
739+
SELECT JSON_QUERY(jsonb '"1"', '$' RETURNING qf_char_domain OMIT QUOTES ERROR ON ERROR);
740+
json_query
741+
------------
742+
1
743+
(1 row)
744+
745+
SELECT JSON_QUERY(jsonb '"1"', '$' RETURNING qf_jsonb_domain OMIT QUOTES ERROR ON ERROR);
746+
json_query
747+
------------
748+
1
749+
(1 row)
750+
751+
DROP DOMAIN qf_char_domain, qf_jsonb_domain;
737752
SELECT JSON_QUERY(jsonb '[]', '$[*]');
738753
json_query
739754
------------

‎src/test/regress/sql/sqljson_queryfuncs.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ SELECT JSON_QUERY(jsonb'{"rec": "{1,2,3}"}', '$.rec' returning int[] keep quotes
214214
SELECT JSON_QUERY(jsonb'{"rec": "[1,2]"}','$.rec' returning int4range omit quotes);
215215
SELECT JSON_QUERY(jsonb'{"rec": "[1,2]"}','$.rec' returning int4range keep quotes);
216216
SELECT JSON_QUERY(jsonb'{"rec": "[1,2]"}','$.rec' returning int4range keep quotes erroron error);
217+
CREATEDOMAINqf_char_domainASchar(1);
218+
CREATEDOMAINqf_jsonb_domainAS jsonb;
219+
SELECT JSON_QUERY(jsonb'"1"','$' RETURNING qf_char_domain OMIT QUOTES ERRORON ERROR);
220+
SELECT JSON_QUERY(jsonb'"1"','$' RETURNING qf_jsonb_domain OMIT QUOTES ERRORON ERROR);
221+
DROPDOMAIN qf_char_domain, qf_jsonb_domain;
217222

218223
SELECT JSON_QUERY(jsonb'[]','$[*]');
219224
SELECT JSON_QUERY(jsonb'[]','$[*]'NULLON EMPTY);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp