From 908e234733574545866045c7d5f93d4dd50ef66d Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Thu, 11 Jun 2015 10:06:58 -0400 Subject: [PATCH] Rename jsonb - text[] operator to #- to avoid ambiguity. Following recent discussion on -hackers. The underlying function is also renamed to jsonb_delete_path. The regression tests now don't need ugly type casts to avoid the ambiguity, so they are also removed. Catalog version bumped. --- doc/src/sgml/func.sgml | 4 +-- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_operator.h | 8 +++--- src/include/catalog/pg_proc.h | 2 +- src/test/regress/expected/jsonb.out | 36 +++++++++++++-------------- src/test/regress/expected/jsonb_1.out | 36 +++++++++++++-------------- src/test/regress/sql/jsonb.sql | 30 +++++++++++----------- 7 files changed, 59 insertions(+), 59 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index ff00d43dae..650051b044 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10316,10 +10316,10 @@ table2-mapping '["a", "b"]'::jsonb - 1 - - + #- text[] Delete the field or element with specified path - '["a", {"b":1}]'::jsonb - '{1,b}'::text[] + '["a", {"b":1}]'::jsonb #- '{1,b}' diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 5ca4af4da4..de9018b957 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201505311 +#define CATALOG_VERSION_NO 201506111 #endif diff --git a/src/include/catalog/pg_operator.h b/src/include/catalog/pg_operator.h index 773f4fd731..26c9d4e4f7 100644 --- a/src/include/catalog/pg_operator.h +++ b/src/include/catalog/pg_operator.h @@ -1816,11 +1816,11 @@ DESCR("is contained by"); DATA(insert OID = 3284 ( "||" PGNSP PGUID b f f 3802 3802 3802 0 0 jsonb_concat - - )); DESCR("concatenate"); DATA(insert OID = 3285 ( "-" PGNSP PGUID b f f 3802 25 3802 0 0 3302 - - )); -DESCR("delete"); +DESCR("delete object field"); DATA(insert OID = 3286 ( "-" PGNSP PGUID b f f 3802 23 3802 0 0 3303 - - )); -DESCR("delete"); -DATA(insert OID = 3287 ( "-" PGNSP PGUID b f f 3802 1009 3802 0 0 3304 - - )); -DESCR("delete"); +DESCR("delete array element"); +DATA(insert OID = 3287 ( "#-" PGNSP PGUID b f f 3802 1009 3802 0 0 jsonb_delete_path - - )); +DESCR("delete path"); /* * function prototypes diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index fe06ec285d..6b3d1949ef 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -4858,7 +4858,7 @@ DESCR("GIN support"); DATA(insert OID = 3301 ( jsonb_concat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3802 "3802 3802" _null_ _null_ _null_ _null_ _null_ jsonb_concat _null_ _null_ _null_ )); DATA(insert OID = 3302 ( jsonb_delete PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3802 "3802 25" _null_ _null_ _null_ _null_ _null_ jsonb_delete _null_ _null_ _null_ )); DATA(insert OID = 3303 ( jsonb_delete PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3802 "3802 23" _null_ _null_ _null_ _null_ _null_ jsonb_delete_idx _null_ _null_ _null_ )); -DATA(insert OID = 3304 ( jsonb_delete PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3802 "3802 1009" _null_ _null_ _null_ _null_ _null_ jsonb_delete_path _null_ _null_ _null_ )); +DATA(insert OID = 3304 ( jsonb_delete_path PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3802 "3802 1009" _null_ _null_ _null_ _null_ _null_ jsonb_delete_path _null_ _null_ _null_ )); DATA(insert OID = 3305 ( jsonb_set PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 3802 "3802 1009 3802 16" _null_ _null_ _null_ _null_ _null_ jsonb_set _null_ _null_ _null_ )); DESCR("Set part of a jsonb"); DATA(insert OID = 3306 ( jsonb_pretty PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "3802" _null_ _null_ _null_ _null_ _null_ jsonb_pretty _null_ _null_ _null_ )); diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expected/jsonb.out index e6654d4715..171520275d 100644 --- a/src/test/regress/expected/jsonb.out +++ b/src/test/regress/expected/jsonb.out @@ -2947,37 +2947,37 @@ select jsonb_delete('{"a":1 , "b":2, "c":3}'::jsonb, 'd'); {"a": 1, "b": 2, "c": 3} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'a'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'a'; ?column? ------------------ {"b": 2, "c": 3} (1 row) -select '{"a":null , "b":2, "c":3}'::jsonb - 'a'::text; +select '{"a":null , "b":2, "c":3}'::jsonb - 'a'; ?column? ------------------ {"b": 2, "c": 3} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'b'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'b'; ?column? ------------------ {"a": 1, "c": 3} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'c'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'c'; ?column? ------------------ {"a": 1, "b": 2} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'd'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'd'; ?column? -------------------------- {"a": 1, "b": 2, "c": 3} (1 row) -select pg_column_size('{"a":1 , "b":2, "c":3}'::jsonb - 'b'::text) = pg_column_size('{"a":1, "b":2}'::jsonb); +select pg_column_size('{"a":1 , "b":2, "c":3}'::jsonb - 'b') = pg_column_size('{"a":1, "b":2}'::jsonb); ?column? ---------- t @@ -3091,37 +3091,37 @@ select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::j {"a": 1, "b": [1, {"f": "test"}], "c": {"1": 2}, "d": {"1": [2, 3]}, "n": null} (1 row) -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{n}'::text[]); - jsonb_delete +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{n}'); + jsonb_delete_path ---------------------------------------------------------- {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [2, 3]}} (1 row) -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{b,-1}'::text[]); - jsonb_delete +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{b,-1}'); + jsonb_delete_path ------------------------------------------------------------------ {"a": 1, "b": [1], "c": {"1": 2}, "d": {"1": [2, 3]}, "n": null} (1 row) -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{d,1,0}'::text[]); - jsonb_delete +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{d,1,0}'); + jsonb_delete_path ------------------------------------------------------------------ {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [3]}, "n": null} (1 row) -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{n}'::text[]; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{n}'; ?column? ---------------------------------------------------------- {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [2, 3]}} (1 row) -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{b,-1}'::text[]; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{b,-1}'; ?column? ------------------------------------------------------------------ {"a": 1, "b": [1], "c": {"1": 2}, "d": {"1": [2, 3]}, "n": null} (1 row) -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{d,1,0}'::text[]; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{d,1,0}'; ?column? ------------------------------------------------------------------ {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [3]}, "n": null} @@ -3152,15 +3152,15 @@ select '[]'::jsonb - 1; [] (1 row) -select '"a"'::jsonb - '{a}'::text[]; -- error +select '"a"'::jsonb #- '{a}'; -- error ERROR: cannot delete path in scalar -select '{}'::jsonb - '{a}'::text[]; +select '{}'::jsonb #- '{a}'; ?column? ---------- {} (1 row) -select '[]'::jsonb - '{a}'::text[]; +select '[]'::jsonb #- '{a}'; ?column? ---------- [] diff --git a/src/test/regress/expected/jsonb_1.out b/src/test/regress/expected/jsonb_1.out index 0a1ec93456..864d85c605 100644 --- a/src/test/regress/expected/jsonb_1.out +++ b/src/test/regress/expected/jsonb_1.out @@ -2947,37 +2947,37 @@ select jsonb_delete('{"a":1 , "b":2, "c":3}'::jsonb, 'd'); {"a": 1, "b": 2, "c": 3} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'a'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'a'; ?column? ------------------ {"b": 2, "c": 3} (1 row) -select '{"a":null , "b":2, "c":3}'::jsonb - 'a'::text; +select '{"a":null , "b":2, "c":3}'::jsonb - 'a'; ?column? ------------------ {"b": 2, "c": 3} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'b'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'b'; ?column? ------------------ {"a": 1, "c": 3} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'c'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'c'; ?column? ------------------ {"a": 1, "b": 2} (1 row) -select '{"a":1 , "b":2, "c":3}'::jsonb - 'd'::text; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'd'; ?column? -------------------------- {"a": 1, "b": 2, "c": 3} (1 row) -select pg_column_size('{"a":1 , "b":2, "c":3}'::jsonb - 'b'::text) = pg_column_size('{"a":1, "b":2}'::jsonb); +select pg_column_size('{"a":1 , "b":2, "c":3}'::jsonb - 'b') = pg_column_size('{"a":1, "b":2}'::jsonb); ?column? ---------- t @@ -3091,37 +3091,37 @@ select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::j {"a": 1, "b": [1, {"f": "test"}], "c": {"1": 2}, "d": {"1": [2, 3]}, "n": null} (1 row) -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{n}'::text[]); - jsonb_delete +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{n}'); + jsonb_delete_path ---------------------------------------------------------- {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [2, 3]}} (1 row) -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{b,-1}'::text[]); - jsonb_delete +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{b,-1}'); + jsonb_delete_path ------------------------------------------------------------------ {"a": 1, "b": [1], "c": {"1": 2}, "d": {"1": [2, 3]}, "n": null} (1 row) -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{d,1,0}'::text[]); - jsonb_delete +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{d,1,0}'); + jsonb_delete_path ------------------------------------------------------------------ {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [3]}, "n": null} (1 row) -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{n}'::text[]; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{n}'; ?column? ---------------------------------------------------------- {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [2, 3]}} (1 row) -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{b,-1}'::text[]; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{b,-1}'; ?column? ------------------------------------------------------------------ {"a": 1, "b": [1], "c": {"1": 2}, "d": {"1": [2, 3]}, "n": null} (1 row) -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{d,1,0}'::text[]; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{d,1,0}'; ?column? ------------------------------------------------------------------ {"a": 1, "b": [1, 2], "c": {"1": 2}, "d": {"1": [3]}, "n": null} @@ -3152,15 +3152,15 @@ select '[]'::jsonb - 1; [] (1 row) -select '"a"'::jsonb - '{a}'::text[]; -- error +select '"a"'::jsonb #- '{a}'; -- error ERROR: cannot delete path in scalar -select '{}'::jsonb - '{a}'::text[]; +select '{}'::jsonb #- '{a}'; ?column? ---------- {} (1 row) -select '[]'::jsonb - '{a}'::text[]; +select '[]'::jsonb #- '{a}'; ?column? ---------- [] diff --git a/src/test/regress/sql/jsonb.sql b/src/test/regress/sql/jsonb.sql index 29c82a2a62..a25a19d7f0 100644 --- a/src/test/regress/sql/jsonb.sql +++ b/src/test/regress/sql/jsonb.sql @@ -722,12 +722,12 @@ select jsonb_delete('{"a":null , "b":2, "c":3}'::jsonb, 'a'); select jsonb_delete('{"a":1 , "b":2, "c":3}'::jsonb, 'b'); select jsonb_delete('{"a":1 , "b":2, "c":3}'::jsonb, 'c'); select jsonb_delete('{"a":1 , "b":2, "c":3}'::jsonb, 'd'); -select '{"a":1 , "b":2, "c":3}'::jsonb - 'a'::text; -select '{"a":null , "b":2, "c":3}'::jsonb - 'a'::text; -select '{"a":1 , "b":2, "c":3}'::jsonb - 'b'::text; -select '{"a":1 , "b":2, "c":3}'::jsonb - 'c'::text; -select '{"a":1 , "b":2, "c":3}'::jsonb - 'd'::text; -select pg_column_size('{"a":1 , "b":2, "c":3}'::jsonb - 'b'::text) = pg_column_size('{"a":1, "b":2}'::jsonb); +select '{"a":1 , "b":2, "c":3}'::jsonb - 'a'; +select '{"a":null , "b":2, "c":3}'::jsonb - 'a'; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'b'; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'c'; +select '{"a":1 , "b":2, "c":3}'::jsonb - 'd'; +select pg_column_size('{"a":1 , "b":2, "c":3}'::jsonb - 'b') = pg_column_size('{"a":1, "b":2}'::jsonb); select '["a","b","c"]'::jsonb - 3; select '["a","b","c"]'::jsonb - 2; @@ -751,13 +751,13 @@ select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::j select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{b,-1}', '"test"'); select jsonb_set('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb, '{b,-1}', '{"f": "test"}'); -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{n}'::text[]); -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{b,-1}'::text[]); -select jsonb_delete('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{d,1,0}'::text[]); +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{n}'); +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{b,-1}'); +select jsonb_delete_path('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}', '{d,1,0}'); -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{n}'::text[]; -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{b,-1}'::text[]; -select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb - '{d,1,0}'::text[]; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{n}'; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{b,-1}'; +select '{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}'::jsonb #- '{d,1,0}'; -- empty structure and error conditions for delete and replace @@ -768,9 +768,9 @@ select '[]'::jsonb - 'a'; select '"a"'::jsonb - 1; -- error select '{}'::jsonb - 1; -- error select '[]'::jsonb - 1; -select '"a"'::jsonb - '{a}'::text[]; -- error -select '{}'::jsonb - '{a}'::text[]; -select '[]'::jsonb - '{a}'::text[]; +select '"a"'::jsonb #- '{a}'; -- error +select '{}'::jsonb #- '{a}'; +select '[]'::jsonb #- '{a}'; select jsonb_set('"a"','{a}','"b"'); --error select jsonb_set('{}','{a}','"b"', false); select jsonb_set('[]','{1}','"b"', false);