Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
-- 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 has been found.
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 has been found. |      | 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:  Input data 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:  Input data 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:  Input data 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:  Input data 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}]" | Input data 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}]" | Input data 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"}]" | Input data 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}]" | Input data 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 has been found.
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:  Key "ndistinct" has an incorrect 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:  Key "attributes" has an incorrect 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:  Key "ndistinct" has an incorrect 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 has been found at an unexpected location.
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 has been found at an unexpected location.
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 has been found at an unexpected location.
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 has been found: 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 has been found: -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 has been found.
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 has been found.
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 has been found. |      | 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}]" | Key "ndistinct" has an incorrect 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}]" | Key "attributes" has an incorrect 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"}]" | Key "ndistinct" has an incorrect 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 has been found at an unexpected location. |      | 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 has been found at an unexpected location. |      | 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 has been found at an unexpected location. |      | 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 has been found. |      | 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 has been found: -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 has been found. |      | 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 has been found. |      | 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 has been found: 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 has been found: 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 has been 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 has been 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)