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

Commitb81c7b4

Browse files
committed
Desupport jsonb subscript deletion on objects
Supporting deletion of JSON pairs within jsonb objects using anarray-style integer subscript allowed for surprising outcomes. This wasmostly due to the implementation-defined ordering of pairs withinobjects for jsonb.It also seems desirable to make jsonb integer subscript deletionconsistent with the 9.4 era general purpose integer subscriptingoperator for jsonb (although that operator returns NULL when an objectis encountered, while we prefer here to throw an error).Peter Geoghegan, following discussion on -hackers.
1 parentd23a3a6 commitb81c7b4

File tree

5 files changed

+13
-120
lines changed

5 files changed

+13
-120
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10309,8 +10309,9 @@ table2-mapping
1030910309
<row>
1031010310
<entry><literal>-</literal></entry>
1031110311
<entry><type>integer</type></entry>
10312-
<entry>Delete the field or element with specified index (Negative
10313-
integers count from the end)</entry>
10312+
<entry>Delete the array element with specified index (Negative
10313+
integers count from the end). Throws an error if top level
10314+
container is not an array.</entry>
1031410315
<entry><literal>'["a", "b"]'::jsonb - 1 </literal></entry>
1031510316
</row>
1031610317
<row>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,6 +3400,11 @@ jsonb_delete_idx(PG_FUNCTION_ARGS)
34003400
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
34013401
errmsg("cannot delete from scalar")));
34023402

3403+
if (JB_ROOT_IS_OBJECT(in))
3404+
ereport(ERROR,
3405+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3406+
errmsg("cannot delete from object using integer subscript")));
3407+
34033408
if (JB_ROOT_COUNT(in)==0)
34043409
PG_RETURN_JSONB(in);
34053410

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

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,54 +3031,6 @@ select '["a","b","c"]'::jsonb - -4;
30313031
["a", "b", "c"]
30323032
(1 row)
30333033

3034-
select '{"a":1, "b":2, "c":3}'::jsonb - 3;
3035-
?column?
3036-
--------------------------
3037-
{"a": 1, "b": 2, "c": 3}
3038-
(1 row)
3039-
3040-
select '{"a":1, "b":2, "c":3}'::jsonb - 2;
3041-
?column?
3042-
------------------
3043-
{"a": 1, "b": 2}
3044-
(1 row)
3045-
3046-
select '{"a":1, "b":2, "c":3}'::jsonb - 1;
3047-
?column?
3048-
------------------
3049-
{"a": 1, "c": 3}
3050-
(1 row)
3051-
3052-
select '{"a":1, "b":2, "c":3}'::jsonb - 0;
3053-
?column?
3054-
------------------
3055-
{"b": 2, "c": 3}
3056-
(1 row)
3057-
3058-
select '{"a":1, "b":2, "c":3}'::jsonb - -1;
3059-
?column?
3060-
------------------
3061-
{"a": 1, "b": 2}
3062-
(1 row)
3063-
3064-
select '{"a":1, "b":2, "c":3}'::jsonb - -2;
3065-
?column?
3066-
------------------
3067-
{"a": 1, "c": 3}
3068-
(1 row)
3069-
3070-
select '{"a":1, "b":2, "c":3}'::jsonb - -3;
3071-
?column?
3072-
------------------
3073-
{"b": 2, "c": 3}
3074-
(1 row)
3075-
3076-
select '{"a":1, "b":2, "c":3}'::jsonb - -4;
3077-
?column?
3078-
--------------------------
3079-
{"a": 1, "b": 2, "c": 3}
3080-
(1 row)
3081-
30823034
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{n}', '[1,2,3]');
30833035
jsonb_set
30843036
--------------------------------------------------------------------------
@@ -3192,12 +3144,8 @@ select '[]'::jsonb - 'a';
31923144

31933145
select '"a"'::jsonb - 1; -- error
31943146
ERROR: cannot delete from scalar
3195-
select '{}'::jsonb - 1 ;
3196-
?column?
3197-
----------
3198-
{}
3199-
(1 row)
3200-
3147+
select '{}'::jsonb - 1; -- error
3148+
ERROR: cannot delete from object using integer subscript
32013149
select '[]'::jsonb - 1;
32023150
?column?
32033151
----------

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

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,54 +3031,6 @@ select '["a","b","c"]'::jsonb - -4;
30313031
["a", "b", "c"]
30323032
(1 row)
30333033

3034-
select '{"a":1, "b":2, "c":3}'::jsonb - 3;
3035-
?column?
3036-
--------------------------
3037-
{"a": 1, "b": 2, "c": 3}
3038-
(1 row)
3039-
3040-
select '{"a":1, "b":2, "c":3}'::jsonb - 2;
3041-
?column?
3042-
------------------
3043-
{"a": 1, "b": 2}
3044-
(1 row)
3045-
3046-
select '{"a":1, "b":2, "c":3}'::jsonb - 1;
3047-
?column?
3048-
------------------
3049-
{"a": 1, "c": 3}
3050-
(1 row)
3051-
3052-
select '{"a":1, "b":2, "c":3}'::jsonb - 0;
3053-
?column?
3054-
------------------
3055-
{"b": 2, "c": 3}
3056-
(1 row)
3057-
3058-
select '{"a":1, "b":2, "c":3}'::jsonb - -1;
3059-
?column?
3060-
------------------
3061-
{"a": 1, "b": 2}
3062-
(1 row)
3063-
3064-
select '{"a":1, "b":2, "c":3}'::jsonb - -2;
3065-
?column?
3066-
------------------
3067-
{"a": 1, "c": 3}
3068-
(1 row)
3069-
3070-
select '{"a":1, "b":2, "c":3}'::jsonb - -3;
3071-
?column?
3072-
------------------
3073-
{"b": 2, "c": 3}
3074-
(1 row)
3075-
3076-
select '{"a":1, "b":2, "c":3}'::jsonb - -4;
3077-
?column?
3078-
--------------------------
3079-
{"a": 1, "b": 2, "c": 3}
3080-
(1 row)
3081-
30823034
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{n}', '[1,2,3]');
30833035
jsonb_set
30843036
--------------------------------------------------------------------------
@@ -3192,12 +3144,8 @@ select '[]'::jsonb - 'a';
31923144

31933145
select '"a"'::jsonb - 1; -- error
31943146
ERROR: cannot delete from scalar
3195-
select '{}'::jsonb - 1 ;
3196-
?column?
3197-
----------
3198-
{}
3199-
(1 row)
3200-
3147+
select '{}'::jsonb - 1; -- error
3148+
ERROR: cannot delete from object using integer subscript
32013149
select '[]'::jsonb - 1;
32023150
?column?
32033151
----------

‎src/test/regress/sql/jsonb.sql

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,6 @@ select '["a","b","c"]'::jsonb - -2;
738738
select'["a","b","c"]'::jsonb--3;
739739
select'["a","b","c"]'::jsonb--4;
740740

741-
select'{"a":1, "b":2, "c":3}'::jsonb-3;
742-
select'{"a":1, "b":2, "c":3}'::jsonb-2;
743-
select'{"a":1, "b":2, "c":3}'::jsonb-1;
744-
select'{"a":1, "b":2, "c":3}'::jsonb-0;
745-
select'{"a":1, "b":2, "c":3}'::jsonb--1;
746-
select'{"a":1, "b":2, "c":3}'::jsonb--2;
747-
select'{"a":1, "b":2, "c":3}'::jsonb--3;
748-
select'{"a":1, "b":2, "c":3}'::jsonb--4;
749-
750741
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb,'{n}','[1,2,3]');
751742
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb,'{b,-1}','[1,2,3]');
752743
select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb,'{d,1,0}','[1,2,3]');
@@ -775,7 +766,7 @@ select '"a"'::jsonb - 'a'; -- error
775766
select'{}'::jsonb-'a';
776767
select'[]'::jsonb-'a';
777768
select'"a"'::jsonb-1;-- error
778-
select'{}'::jsonb-1 ;
769+
select'{}'::jsonb-1;-- error
779770
select'[]'::jsonb-1;
780771
select'"a"'::jsonb-'{a}'::text[];-- error
781772
select'{}'::jsonb-'{a}'::text[];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp