@@ -233,23 +233,27 @@ array_in(PG_FUNCTION_ARGS)
233
233
errmsg ("number of array dimensions (%d) exceeds the maximum allowed (%d)" ,
234
234
ndim + 1 , MAXDIM )));
235
235
236
- for (q = p ; isdigit ((unsigned char ) * q ) || (* q == '-' ) || (* q == '+' ); q ++ );
236
+ for (q = p ; isdigit ((unsigned char ) * q ) || (* q == '-' ) || (* q == '+' ); q ++ )
237
+ /* skip */ ;
237
238
if (q == p ) /* no digits? */
238
239
ereport (ERROR ,
239
240
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
240
- errmsg ("missing dimension value" )));
241
+ errmsg ("malformed array literal: \"%s\"" , string ),
242
+ errdetail ("\"[\" must introduce explicitly-specified array dimensions." )));
241
243
242
244
if (* q == ':' )
243
245
{
244
246
/* [m:n] format */
245
247
* q = '\0' ;
246
248
lBound [ndim ] = atoi (p );
247
249
p = q + 1 ;
248
- for (q = p ; isdigit ((unsigned char ) * q ) || (* q == '-' ) || (* q == '+' ); q ++ );
250
+ for (q = p ; isdigit ((unsigned char ) * q ) || (* q == '-' ) || (* q == '+' ); q ++ )
251
+ /* skip */ ;
249
252
if (q == p ) /* no digits? */
250
253
ereport (ERROR ,
251
254
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
252
- errmsg ("missing dimension value" )));
255
+ errmsg ("malformed array literal: \"%s\"" , string ),
256
+ errdetail ("Missing array dimension value." )));
253
257
}
254
258
else
255
259
{
@@ -259,7 +263,9 @@ array_in(PG_FUNCTION_ARGS)
259
263
if (* q != ']' )
260
264
ereport (ERROR ,
261
265
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
262
- errmsg ("missing \"]\" in array dimensions" )));
266
+ errmsg ("malformed array literal: \"%s\"" , string ),
267
+ errdetail ("Missing \"%s\" after array dimensions." ,
268
+ "]" )));
263
269
264
270
* q = '\0' ;
265
271
ub = atoi (p );
@@ -279,7 +285,8 @@ array_in(PG_FUNCTION_ARGS)
279
285
if (* p != '{' )
280
286
ereport (ERROR ,
281
287
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
282
- errmsg ("array value must start with \"{\" or dimension information" )));
288
+ errmsg ("malformed array literal: \"%s\"" , string ),
289
+ errdetail ("Array value must start with \"{\" or dimension information." )));
283
290
ndim = ArrayCount (p , dim , typdelim );
284
291
for (i = 0 ; i < ndim ; i ++ )
285
292
lBound [i ] = 1 ;
@@ -293,7 +300,9 @@ array_in(PG_FUNCTION_ARGS)
293
300
if (strncmp (p , ASSGN , strlen (ASSGN )) != 0 )
294
301
ereport (ERROR ,
295
302
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
296
- errmsg ("missing assignment operator" )));
303
+ errmsg ("malformed array literal: \"%s\"" , string ),
304
+ errdetail ("Missing \"%s\" after array dimensions." ,
305
+ ASSGN )));
297
306
p += strlen (ASSGN );
298
307
while (array_isspace (* p ))
299
308
p ++ ;
@@ -305,18 +314,21 @@ array_in(PG_FUNCTION_ARGS)
305
314
if (* p != '{' )
306
315
ereport (ERROR ,
307
316
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
308
- errmsg ("array value must start with \"{\" or dimension information" )));
317
+ errmsg ("malformed array literal: \"%s\"" , string ),
318
+ errdetail ("Array contents must start with \"{\"." )));
309
319
ndim_braces = ArrayCount (p , dim_braces , typdelim );
310
320
if (ndim_braces != ndim )
311
321
ereport (ERROR ,
312
322
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
313
- errmsg ("array dimensions incompatible with array literal" )));
323
+ errmsg ("malformed array literal: \"%s\"" , string ),
324
+ errdetail ("Specified array dimensions do not match array contents." )));
314
325
for (i = 0 ; i < ndim ; ++ i )
315
326
{
316
327
if (dim [i ] != dim_braces [i ])
317
328
ereport (ERROR ,
318
329
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
319
- errmsg ("array dimensions incompatible with array literal" )));
330
+ errmsg ("malformed array literal: \"%s\"" , string ),
331
+ errdetail ("Specified array dimensions do not match array contents." )));
320
332
}
321
333
}
322
334
@@ -446,7 +458,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
446
458
/* Signal a premature end of the string */
447
459
ereport (ERROR ,
448
460
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
449
- errmsg ("malformed array literal: \"%s\"" , str )));
461
+ errmsg ("malformed array literal: \"%s\"" , str ),
462
+ errdetail ("Unexpected end of input." )));
450
463
break ;
451
464
case '\\' :
452
465
@@ -461,7 +474,9 @@ ArrayCount(const char *str, int *dim, char typdelim)
461
474
parse_state != ARRAY_ELEM_DELIMITED )
462
475
ereport (ERROR ,
463
476
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
464
- errmsg ("malformed array literal: \"%s\"" , str )));
477
+ errmsg ("malformed array literal: \"%s\"" , str ),
478
+ errdetail ("Unexpected \"%c\" character." ,
479
+ '\\' )));
465
480
if (parse_state != ARRAY_QUOTED_ELEM_STARTED )
466
481
parse_state = ARRAY_ELEM_STARTED ;
467
482
/* skip the escaped character */
@@ -470,7 +485,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
470
485
else
471
486
ereport (ERROR ,
472
487
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
473
- errmsg ("malformed array literal: \"%s\"" , str )));
488
+ errmsg ("malformed array literal: \"%s\"" , str ),
489
+ errdetail ("Unexpected end of input." )));
474
490
break ;
475
491
case '\"' :
476
492
@@ -484,7 +500,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
484
500
parse_state != ARRAY_ELEM_DELIMITED )
485
501
ereport (ERROR ,
486
502
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
487
- errmsg ("malformed array literal: \"%s\"" , str )));
503
+ errmsg ("malformed array literal: \"%s\"" , str ),
504
+ errdetail ("Unexpected array element." )));
488
505
in_quotes = !in_quotes ;
489
506
if (in_quotes )
490
507
parse_state = ARRAY_QUOTED_ELEM_STARTED ;
@@ -504,7 +521,9 @@ ArrayCount(const char *str, int *dim, char typdelim)
504
521
parse_state != ARRAY_LEVEL_DELIMITED )
505
522
ereport (ERROR ,
506
523
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
507
- errmsg ("malformed array literal: \"%s\"" , str )));
524
+ errmsg ("malformed array literal: \"%s\"" , str ),
525
+ errdetail ("Unexpected \"%c\" character." ,
526
+ '{' )));
508
527
parse_state = ARRAY_LEVEL_STARTED ;
509
528
if (nest_level >= MAXDIM )
510
529
ereport (ERROR ,
@@ -532,21 +551,25 @@ ArrayCount(const char *str, int *dim, char typdelim)
532
551
!(nest_level == 1 && parse_state == ARRAY_LEVEL_STARTED ))
533
552
ereport (ERROR ,
534
553
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
535
- errmsg ("malformed array literal: \"%s\"" , str )));
554
+ errmsg ("malformed array literal: \"%s\"" , str ),
555
+ errdetail ("Unexpected \"%c\" character." ,
556
+ '}' )));
536
557
parse_state = ARRAY_LEVEL_COMPLETED ;
537
558
if (nest_level == 0 )
538
559
ereport (ERROR ,
539
560
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
540
- errmsg ("malformed array literal: \"%s\"" , str )));
561
+ errmsg ("malformed array literal: \"%s\"" , str ),
562
+ errdetail ("Unmatched \"%c\" character." , '}' )));
541
563
nest_level -- ;
542
564
543
565
if (nelems_last [nest_level ] != 0 &&
544
566
nelems [nest_level ] != nelems_last [nest_level ])
545
567
ereport (ERROR ,
546
568
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
547
- errmsg ("multidimensional arrays must have "
548
- "array expressions with matching "
549
- "dimensions" )));
569
+ errmsg ("malformed array literal: \"%s\"" , str ),
570
+ errdetail ("Multidimensional arrays must have "
571
+ "sub-arrays with matching "
572
+ "dimensions." )));
550
573
nelems_last [nest_level ] = nelems [nest_level ];
551
574
nelems [nest_level ] = 1 ;
552
575
if (nest_level == 0 )
@@ -577,7 +600,9 @@ ArrayCount(const char *str, int *dim, char typdelim)
577
600
parse_state != ARRAY_LEVEL_COMPLETED )
578
601
ereport (ERROR ,
579
602
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
580
- errmsg ("malformed array literal: \"%s\"" , str )));
603
+ errmsg ("malformed array literal: \"%s\"" , str ),
604
+ errdetail ("Unexpected \"%c\" character." ,
605
+ typdelim )));
581
606
if (parse_state == ARRAY_LEVEL_COMPLETED )
582
607
parse_state = ARRAY_LEVEL_DELIMITED ;
583
608
else
@@ -598,7 +623,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
598
623
parse_state != ARRAY_ELEM_DELIMITED )
599
624
ereport (ERROR ,
600
625
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
601
- errmsg ("malformed array literal: \"%s\"" , str )));
626
+ errmsg ("malformed array literal: \"%s\"" , str ),
627
+ errdetail ("Unexpected array element." )));
602
628
parse_state = ARRAY_ELEM_STARTED ;
603
629
}
604
630
}
@@ -617,7 +643,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
617
643
if (!array_isspace (* ptr ++ ))
618
644
ereport (ERROR ,
619
645
(errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
620
- errmsg ("malformed array literal: \"%s\"" , str )));
646
+ errmsg ("malformed array literal: \"%s\"" , str ),
647
+ errdetail ("Junk after closing right brace." )));
621
648
}
622
649
623
650
/* special case for an empty array */
@@ -704,7 +731,8 @@ ReadArrayStr(char *arrayStr,
704
731
* character.
705
732
*
706
733
* The error checking in this routine is mostly pro-forma, since we expect
707
- * that ArrayCount() already validated the string.
734
+ * that ArrayCount() already validated the string. So we don't bother
735
+ * with errdetail messages.
708
736
*/
709
737
srcptr = arrayStr ;
710
738
while (!eoArray )
0 commit comments