mirror of https://github.com/postgres/postgres
pg_ndistinct is used as data type for the contents of ndistinct extended
statistics. This new input function consumes the format that has been
established by 1f927cce44 for the output function of pg_ndistinct,
enforcing some sanity checks for:
- Checks for the input object, which should be a one-dimension array
with correct attributes and values.
- The key names: "attributes", "ndistinct". Both are required, other
key names are blocked.
- Value types for each key: "attributes" requires an array of integers,
and "ndistinct" an integer.
- List of attributes. Note that this enforces a check so as an
attribute list has to be a subset of the longest attribute list found.
This does not enforce that a full group of attribute sets exist, based
on how the groups are generated when the ndistinct objects are
generated, making the list of ndistinct items a bit loose. Note a check
would still be required at import to see if the attributes listed match
with the attribute numbers set in the definition of a statistics object.
- Based on the discussion, the checks on the values are loose, as there
is also an argument for potentially stats injection. The relation and
attribute level stats follow the same line of argument for the values.
This is required for a follow-up patch that aims to implement the import
of extended statistics. Some tests are added to check the code paths of
the JSON parser checking the shape of the pg_ndistinct inputs, with 90%
of code coverage reached. The tests are located in their own new test
file, for clarity.
Author: Corey Huinker <corey.huinker@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Yuefei Shi <shiyuefei1004@gmail.com>
Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com
pull/255/head
parent
cd38b7e773
commit
44eba8f06e
@ -0,0 +1,447 @@ |
||||
-- Tests for type pg_ndistinct |
||||
-- Invalid inputs |
||||
SELECT 'null'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "null" |
||||
LINE 1: SELECT 'null'::pg_ndistinct; |
||||
^ |
||||
DETAIL: Unexpected scalar. |
||||
SELECT '{"a": 1}'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "{"a": 1}" |
||||
LINE 1: SELECT '{"a": 1}'::pg_ndistinct; |
||||
^ |
||||
DETAIL: Initial element must be an array. |
||||
SELECT '[]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[]" |
||||
LINE 1: SELECT '[]'::pg_ndistinct; |
||||
^ |
||||
DETAIL: Item array cannot be empty. |
||||
SELECT '{}'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "{}" |
||||
LINE 1: SELECT '{}'::pg_ndistinct; |
||||
^ |
||||
DETAIL: Initial element must be an array. |
||||
SELECT '[null]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[null]" |
||||
LINE 1: SELECT '[null]'::pg_ndistinct; |
||||
^ |
||||
DETAIL: Item list elements cannot be null. |
||||
SELECT * FROM pg_input_error_info('null', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
--------------------------------+--------------------+------+---------------- |
||||
malformed pg_ndistinct: "null" | Unexpected scalar. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('{"a": 1}', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------------+-----------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "{"a": 1}" | Initial element must be an array. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------+-----------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[]" | Item array cannot be empty. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('{}', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------+-----------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "{}" | Initial element must be an array. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[null]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
----------------------------------+------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[null]" | Item list elements cannot be null. | | 22P02 |
||||
(1 row) |
||||
|
||||
-- Invalid keys |
||||
SELECT '[{"attributes_invalid" : [2,3], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes_invalid" : [2,3], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes_invalid" : [2,3], "ndistinct" : 4}]'::... |
||||
^ |
||||
DETAIL: Only allowed keys are "attributes" and "ndistinct". |
||||
SELECT '[{"attributes" : [2,3], "invalid" : 3, "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "invalid" : 3, "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "invalid" : 3, "ndistinct" :... |
||||
^ |
||||
DETAIL: Only allowed keys are "attributes" and "ndistinct". |
||||
SELECT '[{"attributes" : [2,3], "attributes" : [1,3], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "attributes" : [1,3], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "attributes" : [1,3], "ndist... |
||||
^ |
||||
DETAIL: Multiple "attributes" keys are not allowed. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct"... |
||||
^ |
||||
DETAIL: Multiple "ndistinct" keys are not allowed. |
||||
SELECT * FROM pg_input_error_info('[{"attributes_invalid" : [2,3], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------------+-----------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes_invalid" : [2,3], "ndistinct" : 4}]" | Only allowed keys are "attributes" and "ndistinct". | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "invalid" : 3, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------------------------------------------------------------+-----------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "invalid" : 3, "ndistinct" : 4}]" | Only allowed keys are "attributes" and "ndistinct". | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "attributes" : [1,3], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-------------------------------------------------------------------------------------------+---------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "attributes" : [1,3], "ndistinct" : 4}]" | Multiple "attributes" keys are not allowed. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
--------------------------------------------------------------------------------------+--------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct" : 4}]" | Multiple "ndistinct" keys are not allowed. | | 22P02 |
||||
(1 row) |
||||
|
||||
-- Missing key |
||||
SELECT '[{"attributes" : [2,3]}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3]}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3]}]'::pg_ndistinct; |
||||
^ |
||||
DETAIL: Item must contain "ndistinct" key. |
||||
SELECT '[{"ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"ndistinct" : 4}]'::pg_ndistinct; |
||||
^ |
||||
DETAIL: Item must contain "attributes" key. |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3]}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
----------------------------------------------------+------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3]}]" | Item must contain "ndistinct" key. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------+-------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"ndistinct" : 4}]" | Item must contain "attributes" key. | | 22P02 |
||||
(1 row) |
||||
|
||||
-- Valid keys, too many attributes |
||||
SELECT '[{"attributes" : [1,2,3,4,5,6,7,8,9], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [1,2,3,4,5,6,7,8,9], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [1,2,3,4,5,6,7,8,9], "ndistinct" : ... |
||||
^ |
||||
DETAIL: The "attributes" key must contain an array of at least 2 and no more than 8 attributes. |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1,2,3,4,5,6,7,8,9], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [1,2,3,4,5,6,7,8,9], "ndistinct" : 4}]" | The "attributes" key must contain an array of at least 2 and no more than 8 attributes. | | 22P02 |
||||
(1 row) |
||||
|
||||
-- Special characters |
||||
SELECT '[{"\ud83d" : [1, 2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"\ud83d" : [1, 2], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"\ud83d" : [1, 2], "ndistinct" : 4}]'::pg_ndistinc... |
||||
^ |
||||
DETAIL: Must be valid JSON. |
||||
SELECT '[{"attributes" : [1, 2], "\ud83d" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [1, 2], "\ud83d" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [1, 2], "\ud83d" : 4}]'::pg_ndistin... |
||||
^ |
||||
DETAIL: Must be valid JSON. |
||||
SELECT '[{"attributes" : [1, 2], "ndistinct" : "\ud83d"}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [1, 2], "ndistinct" : "\ud83d"}]" |
||||
LINE 1: SELECT '[{"attributes" : [1, 2], "ndistinct" : "\ud83d"}]'::... |
||||
^ |
||||
DETAIL: Must be valid JSON. |
||||
SELECT '[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]" |
||||
LINE 1: SELECT '[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]'::... |
||||
^ |
||||
DETAIL: Must be valid JSON. |
||||
SELECT * FROM pg_input_error_info('[{"\ud83d" : [1, 2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------------------------------------------+---------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"\ud83d" : [1, 2], "ndistinct" : 4}]" | Must be valid JSON. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1, 2], "\ud83d" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-------------------------------------------------------------------+---------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [1, 2], "\ud83d" : 4}]" | Must be valid JSON. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1, 2], "ndistinct" : "\ud83d"}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------------+---------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [1, 2], "ndistinct" : "\ud83d"}]" | Must be valid JSON. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------------+---------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]" | Must be valid JSON. | | 22P02 |
||||
(1 row) |
||||
|
||||
-- Valid keys, invalid values |
||||
SELECT '[{"attributes" : null, "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : null, "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : null, "ndistinct" : 4}]'::pg_ndisti... |
||||
^ |
||||
DETAIL: Unexpected scalar. |
||||
SELECT '[{"attributes" : [], "ndistinct" : 1}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [], "ndistinct" : 1}]" |
||||
LINE 1: SELECT '[{"attributes" : [], "ndistinct" : 1}]'::pg_ndistinc... |
||||
^ |
||||
DETAIL: The "attributes" key must be a non-empty array. |
||||
SELECT '[{"attributes" : [2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2], "ndistinct" : 4}]'::pg_ndistin... |
||||
^ |
||||
DETAIL: The "attributes" key must contain an array of at least 2 and no more than 8 attributes. |
||||
SELECT '[{"attributes" : [2,null], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,null], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,null], "ndistinct" : 4}]'::pg_nd... |
||||
^ |
||||
DETAIL: Attribute number array cannot be null. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : null}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : null}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : null}]'::pg_nd... |
||||
^ |
||||
DETAIL: Invalid "ndistinct" value. |
||||
SELECT '[{"attributes" : [2,"a"], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,"a"], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,"a"], "ndistinct" : 4}]'::pg_ndi... |
||||
^ |
||||
DETAIL: Invalid "attributes" value. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : "a"}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : "a"}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : "a"}]'::pg_ndi... |
||||
^ |
||||
DETAIL: Invalid "ndistinct" value. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : []}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : []}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : []}]'::pg_ndis... |
||||
^ |
||||
DETAIL: Array found in unexpected place. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : [null]}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : [null]}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : [null]}]'::pg_... |
||||
^ |
||||
DETAIL: Array found in unexpected place. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : [1,null]}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : [1,null]}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : [1,null]}]'::p... |
||||
^ |
||||
DETAIL: Array found in unexpected place. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : {"a": 1}}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : {"a": 1}}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : {"a": 1}}]'::p... |
||||
^ |
||||
DETAIL: Value of "ndistinct" must be an integer. |
||||
SELECT '[{"attributes" : [0,1], "ndistinct" : 1}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [0,1], "ndistinct" : 1}]" |
||||
LINE 1: SELECT '[{"attributes" : [0,1], "ndistinct" : 1}]'::pg_ndist... |
||||
^ |
||||
DETAIL: Invalid "attributes" element: 0. |
||||
SELECT '[{"attributes" : [-7,-9], "ndistinct" : 1}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [-7,-9], "ndistinct" : 1}]" |
||||
LINE 1: SELECT '[{"attributes" : [-7,-9], "ndistinct" : 1}]'::pg_ndi... |
||||
^ |
||||
DETAIL: Invalid "attributes" element: -9. |
||||
SELECT '[{"attributes" : 1, "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : 1, "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : 1, "ndistinct" : 4}]'::pg_ndistinct... |
||||
^ |
||||
DETAIL: Unexpected scalar. |
||||
SELECT '[{"attributes" : "a", "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : "a", "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : "a", "ndistinct" : 4}]'::pg_ndistin... |
||||
^ |
||||
DETAIL: Unexpected scalar. |
||||
SELECT '[{"attributes" : {"a": 1}, "ndistinct" : 1}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : {"a": 1}, "ndistinct" : 1}]" |
||||
LINE 1: SELECT '[{"attributes" : {"a": 1}, "ndistinct" : 1}]'::pg_nd... |
||||
^ |
||||
DETAIL: Value of "attributes" must be an array of attribute numbers. |
||||
SELECT '[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]" |
||||
LINE 1: SELECT '[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]'::... |
||||
^ |
||||
DETAIL: Attribute lists can only contain attribute numbers. |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : null, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
--------------------------------------------------------------------+--------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : null, "ndistinct" : 4}]" | Unexpected scalar. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------------------------------------------+-------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [], "ndistinct" : 1}]" | The "attributes" key must be a non-empty array. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-------------------------------------------------------------------+-----------------------------------------------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2], "ndistinct" : 4}]" | The "attributes" key must contain an array of at least 2 and no more than 8 attributes. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,null], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------------------------------------------------+----------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,null], "ndistinct" : 4}]" | Attribute number array cannot be null. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : null}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------------------------------------------------+----------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : null}]" | Invalid "ndistinct" value. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,"a"], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------+-----------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,"a"], "ndistinct" : 4}]" | Invalid "attributes" value. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : "a"}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------+----------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : "a"}]" | Invalid "ndistinct" value. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : []}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
----------------------------------------------------------------------+----------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : []}]" | Array found in unexpected place. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : [null]}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
--------------------------------------------------------------------------+----------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : [null]}]" | Array found in unexpected place. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : [1,null]}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
----------------------------------------------------------------------------+----------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : [1,null]}]" | Array found in unexpected place. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : {"a": 1}}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
----------------------------------------------------------------------------+------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : {"a": 1}}]" | Value of "ndistinct" must be an integer. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : 1, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------+--------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : 1, "ndistinct" : 4}]" | Unexpected scalar. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [-7,-9], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------+-----------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [-7,-9], "ndistinct" : 1}]" | Invalid "attributes" element: -9. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : 1, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------+--------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : 1, "ndistinct" : 4}]" | Unexpected scalar. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : "a", "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-------------------------------------------------------------------+--------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : "a", "ndistinct" : 4}]" | Unexpected scalar. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : {"a": 1}, "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
------------------------------------------------------------------------+--------------------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : {"a": 1}, "ndistinct" : 1}]" | Value of "attributes" must be an array of attribute numbers. | | 22P02 |
||||
(1 row) |
||||
|
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
-----------------------------------------------------------------------------+-----------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]" | Attribute lists can only contain attribute numbers. | | 22P02 |
||||
(1 row) |
||||
|
||||
-- Duplicated attributes |
||||
SELECT '[{"attributes" : [2,2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,2], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,2], "ndistinct" : 4}]'::pg_ndist... |
||||
^ |
||||
DETAIL: Invalid "attributes" element: 2 cannot follow 2. |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
---------------------------------------------------------------------+--------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,2], "ndistinct" : 4}]" | Invalid "attributes" element: 2 cannot follow 2. | | 22P02 |
||||
(1 row) |
||||
|
||||
-- Duplicated attribute lists. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,3], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,3], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
^ |
||||
DETAIL: Duplicated "attributes" array found: [2, 3] |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,3], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
--------------------------------------------------------------------+---------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : 4},+| Duplicated "attributes" array found: [2, 3] | | 22P02 |
||||
{"attributes" : [2,3], "ndistinct" : 4}]" | | | |
||||
(1 row) |
||||
|
||||
-- Partially-covered attribute lists. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,-1], "ndistinct" : 4}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 4}, |
||||
{"attributes" : [1,3,-1,-2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
ERROR: malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,-1], "ndistinct" : 4}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 4}, |
||||
{"attributes" : [1,3,-1,-2], "ndistinct" : 4}]" |
||||
LINE 1: SELECT '[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
^ |
||||
DETAIL: "attributes" array: [2, 3] must be a subset of array: [1, 3, -1, -2] |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,-1], "ndistinct" : 4}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 4}, |
||||
{"attributes" : [1,3,-1,-2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
message | detail | hint | sql_error_code |
||||
--------------------------------------------------------------------+----------------------------------------------------------------------+------+---------------- |
||||
malformed pg_ndistinct: "[{"attributes" : [2,3], "ndistinct" : 4},+| "attributes" array: [2, 3] must be a subset of array: [1, 3, -1, -2] | | 22P02 |
||||
{"attributes" : [2,-1], "ndistinct" : 4}, +| | | |
||||
{"attributes" : [2,3,-1], "ndistinct" : 4}, +| | | |
||||
{"attributes" : [1,3,-1,-2], "ndistinct" : 4}]" | | | |
||||
(1 row) |
||||
|
||||
-- Valid inputs |
||||
-- Two attributes. |
||||
SELECT '[{"attributes" : [1,2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
pg_ndistinct |
||||
------------------------------------------ |
||||
[{"attributes": [1, 2], "ndistinct": 4}] |
||||
(1 row) |
||||
|
||||
-- Three attributes. |
||||
SELECT '[{"attributes" : [2,-1], "ndistinct" : 1}, |
||||
{"attributes" : [3,-1], "ndistinct" : 2}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 3}]'::pg_ndistinct; |
||||
pg_ndistinct |
||||
-------------------------------------------------------------------------------------------------------------------------------- |
||||
[{"attributes": [2, -1], "ndistinct": 1}, {"attributes": [3, -1], "ndistinct": 2}, {"attributes": [2, 3, -1], "ndistinct": 3}] |
||||
(1 row) |
||||
|
||||
-- Three attributes with only two items. |
||||
SELECT '[{"attributes" : [2,-1], "ndistinct" : 1}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 3}]'::pg_ndistinct; |
||||
pg_ndistinct |
||||
--------------------------------------------------------------------------------------- |
||||
[{"attributes": [2, -1], "ndistinct": 1}, {"attributes": [2, 3, -1], "ndistinct": 3}] |
||||
(1 row) |
||||
|
||||
@ -0,0 +1,106 @@ |
||||
-- Tests for type pg_ndistinct |
||||
|
||||
-- Invalid inputs |
||||
SELECT 'null'::pg_ndistinct; |
||||
SELECT '{"a": 1}'::pg_ndistinct; |
||||
SELECT '[]'::pg_ndistinct; |
||||
SELECT '{}'::pg_ndistinct; |
||||
SELECT '[null]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('null', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('{"a": 1}', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('{}', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[null]', 'pg_ndistinct'); |
||||
-- Invalid keys |
||||
SELECT '[{"attributes_invalid" : [2,3], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "invalid" : 3, "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "attributes" : [1,3], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"attributes_invalid" : [2,3], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "invalid" : 3, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "attributes" : [1,3], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
|
||||
-- Missing key |
||||
SELECT '[{"attributes" : [2,3]}]'::pg_ndistinct; |
||||
SELECT '[{"ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3]}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"ndistinct" : 4}]', 'pg_ndistinct'); |
||||
|
||||
-- Valid keys, too many attributes |
||||
SELECT '[{"attributes" : [1,2,3,4,5,6,7,8,9], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1,2,3,4,5,6,7,8,9], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
|
||||
-- Special characters |
||||
SELECT '[{"\ud83d" : [1, 2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [1, 2], "\ud83d" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [1, 2], "ndistinct" : "\ud83d"}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"\ud83d" : [1, 2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1, 2], "\ud83d" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1, 2], "ndistinct" : "\ud83d"}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
|
||||
-- Valid keys, invalid values |
||||
SELECT '[{"attributes" : null, "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [], "ndistinct" : 1}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,null], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : null}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,"a"], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : "a"}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : []}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : [null]}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : [1,null]}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : {"a": 1}}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [0,1], "ndistinct" : 1}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [-7,-9], "ndistinct" : 1}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : 1, "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : "a", "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : {"a": 1}, "ndistinct" : 1}]'::pg_ndistinct; |
||||
SELECT '[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : null, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,null], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : null}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,"a"], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : "a"}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : []}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : [null]}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : [1,null]}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : {"a": 1}}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : 1, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [-7,-9], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : 1, "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : "a", "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : {"a": 1}, "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]', 'pg_ndistinct'); |
||||
-- Duplicated attributes |
||||
SELECT '[{"attributes" : [2,2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
-- Duplicated attribute lists. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,3], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,3], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
-- Partially-covered attribute lists. |
||||
SELECT '[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,-1], "ndistinct" : 4}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 4}, |
||||
{"attributes" : [1,3,-1,-2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
SELECT * FROM pg_input_error_info('[{"attributes" : [2,3], "ndistinct" : 4}, |
||||
{"attributes" : [2,-1], "ndistinct" : 4}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 4}, |
||||
{"attributes" : [1,3,-1,-2], "ndistinct" : 4}]', 'pg_ndistinct'); |
||||
|
||||
-- Valid inputs |
||||
-- Two attributes. |
||||
SELECT '[{"attributes" : [1,2], "ndistinct" : 4}]'::pg_ndistinct; |
||||
-- Three attributes. |
||||
SELECT '[{"attributes" : [2,-1], "ndistinct" : 1}, |
||||
{"attributes" : [3,-1], "ndistinct" : 2}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 3}]'::pg_ndistinct; |
||||
-- Three attributes with only two items. |
||||
SELECT '[{"attributes" : [2,-1], "ndistinct" : 1}, |
||||
{"attributes" : [2,3,-1], "ndistinct" : 3}]'::pg_ndistinct; |
||||
Loading…
Reference in new issue