Commit 798e2357 authored by Tom Lane's avatar Tom Lane

Rationalize error messages within jsonfuncs.c.

I noticed that the functions in jsonfuncs.c sometimes printed error
messages that claimed I'd called some other function.  Investigation showed
that this was from repurposing code into "worker" functions without taking
much care as to whether it would mention the right SQL-level function if it
threw an error.  Moreover, there was a weird mismash of messages that
contained a fixed function name, messages that used %s for a function name,
and messages that constructed a function name out of spare parts, like
"json%s_populate_record" (which, quite aside from being ugly as sin, wasn't
even sufficient to cover all the cases).  This would put an undue burden on
our long-suffering translators.  Standardize on inserting the SQL function
name with %s so as to reduce the number of translatable strings, and pass
function names around as needed to make sure we can report the right one.
Fix up some gratuitous variations in wording, too.
parent 8d2d7ad5
This diff is collapsed.
...@@ -311,9 +311,9 @@ INSERT INTO test_jsonb VALUES ...@@ -311,9 +311,9 @@ INSERT INTO test_jsonb VALUES
('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), ('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'),
('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); ('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}');
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_object_field (jsonb -> text operator) on a scalar ERROR: cannot call jsonb_object_field (jsonb -> text) on a scalar
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array';
ERROR: cannot call jsonb_object_field (jsonb -> text operator) on an array ERROR: cannot call jsonb_object_field (jsonb -> text) on an array
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'object'; SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'object';
?column? ?column?
---------- ----------
...@@ -327,9 +327,9 @@ SELECT test_json -> 'field2' FROM test_jsonb WHERE json_type = 'object'; ...@@ -327,9 +327,9 @@ SELECT test_json -> 'field2' FROM test_jsonb WHERE json_type = 'object';
(1 row) (1 row)
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on a scalar ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on a scalar
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array'; SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array';
ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on an array ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on an array
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object'; SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object';
?column? ?column?
---------- ----------
...@@ -337,7 +337,7 @@ SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object'; ...@@ -337,7 +337,7 @@ SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object';
(1 row) (1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_array_element (jsonb -> int operator) on a scalar ERROR: cannot call jsonb_array_element (jsonb -> int) on a scalar
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array';
?column? ?column?
---------- ----------
...@@ -351,7 +351,7 @@ SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array'; ...@@ -351,7 +351,7 @@ SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array';
(1 row) (1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object';
ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object ERROR: cannot call jsonb_array_element (jsonb -> int) on an object
SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array';
?column? ?column?
----------- -----------
...@@ -1229,13 +1229,13 @@ SELECT '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::jsonb#>>'{f2,1}'; ...@@ -1229,13 +1229,13 @@ SELECT '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::jsonb#>>'{f2,1}';
-- same on jsonb scalars (expecting errors) -- same on jsonb scalars (expecting errors)
SELECT '42'::jsonb#>array['f2']; SELECT '42'::jsonb#>array['f2'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
SELECT '42'::jsonb#>array['0']; SELECT '42'::jsonb#>array['0'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
SELECT '42'::jsonb#>>array['f2']; SELECT '42'::jsonb#>>array['f2'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
SELECT '42'::jsonb#>>array['0']; SELECT '42'::jsonb#>>array['0'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
-- array_elements -- array_elements
SELECT jsonb_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]'); SELECT jsonb_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]');
jsonb_array_elements jsonb_array_elements
...@@ -1923,7 +1923,7 @@ SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 'e'; ...@@ -1923,7 +1923,7 @@ SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 'e';
(1 row) (1 row)
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 0; --expecting error SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 0; --expecting error
ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object ERROR: cannot call jsonb_array_element (jsonb -> int) on an object
SELECT '["a","b","c",[1,2],null]'::jsonb -> 0; SELECT '["a","b","c",[1,2],null]'::jsonb -> 0;
?column? ?column?
---------- ----------
......
...@@ -311,9 +311,9 @@ INSERT INTO test_jsonb VALUES ...@@ -311,9 +311,9 @@ INSERT INTO test_jsonb VALUES
('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), ('array','["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'),
('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}'); ('object','{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}');
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_object_field (jsonb -> text operator) on a scalar ERROR: cannot call jsonb_object_field (jsonb -> text) on a scalar
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'array';
ERROR: cannot call jsonb_object_field (jsonb -> text operator) on an array ERROR: cannot call jsonb_object_field (jsonb -> text) on an array
SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'object'; SELECT test_json -> 'x' FROM test_jsonb WHERE json_type = 'object';
?column? ?column?
---------- ----------
...@@ -327,9 +327,9 @@ SELECT test_json -> 'field2' FROM test_jsonb WHERE json_type = 'object'; ...@@ -327,9 +327,9 @@ SELECT test_json -> 'field2' FROM test_jsonb WHERE json_type = 'object';
(1 row) (1 row)
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on a scalar ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on a scalar
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array'; SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array';
ERROR: cannot call jsonb_object_field_text (jsonb ->> text operator) on an array ERROR: cannot call jsonb_object_field_text (jsonb ->> text) on an array
SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object'; SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object';
?column? ?column?
---------- ----------
...@@ -337,7 +337,7 @@ SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object'; ...@@ -337,7 +337,7 @@ SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object';
(1 row) (1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar';
ERROR: cannot call jsonb_array_element (jsonb -> int operator) on a scalar ERROR: cannot call jsonb_array_element (jsonb -> int) on a scalar
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'array';
?column? ?column?
---------- ----------
...@@ -351,7 +351,7 @@ SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array'; ...@@ -351,7 +351,7 @@ SELECT test_json -> 9 FROM test_jsonb WHERE json_type = 'array';
(1 row) (1 row)
SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object'; SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'object';
ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object ERROR: cannot call jsonb_array_element (jsonb -> int) on an object
SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array'; SELECT test_json ->> 6 FROM test_jsonb WHERE json_type = 'array';
?column? ?column?
----------- -----------
...@@ -1229,13 +1229,13 @@ SELECT '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::jsonb#>>'{f2,1}'; ...@@ -1229,13 +1229,13 @@ SELECT '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}'::jsonb#>>'{f2,1}';
-- same on jsonb scalars (expecting errors) -- same on jsonb scalars (expecting errors)
SELECT '42'::jsonb#>array['f2']; SELECT '42'::jsonb#>array['f2'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
SELECT '42'::jsonb#>array['0']; SELECT '42'::jsonb#>array['0'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
SELECT '42'::jsonb#>>array['f2']; SELECT '42'::jsonb#>>array['f2'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
SELECT '42'::jsonb#>>array['0']; SELECT '42'::jsonb#>>array['0'];
ERROR: cannot call extract path from a scalar ERROR: cannot extract path from a scalar
-- array_elements -- array_elements
SELECT jsonb_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]'); SELECT jsonb_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]');
jsonb_array_elements jsonb_array_elements
...@@ -1923,7 +1923,7 @@ SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 'e'; ...@@ -1923,7 +1923,7 @@ SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 'e';
(1 row) (1 row)
SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 0; --expecting error SELECT '{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}'::jsonb -> 0; --expecting error
ERROR: cannot call jsonb_array_element (jsonb -> int operator) on an object ERROR: cannot call jsonb_array_element (jsonb -> int) on an object
SELECT '["a","b","c",[1,2],null]'::jsonb -> 0; SELECT '["a","b","c",[1,2],null]'::jsonb -> 0;
?column? ?column?
---------- ----------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment