@@ -565,8 +565,9 @@ parse_partitioning_expression(const Oid relid,
565
565
char * * query_string_out , /* ret value #1 */
566
566
Node * * parsetree_out ) /* ret value #2 */
567
567
{
568
- SelectStmt * select_stmt ;
569
- List * parsetree_list ;
568
+ SelectStmt * select_stmt ;
569
+ List * parsetree_list ;
570
+ MemoryContext old_mcxt ;
570
571
571
572
const char * sql = "SELECT (%s) FROM ONLY %s.%s" ;
572
573
char * relname = get_rel_name (relid ),
@@ -575,7 +576,31 @@ parse_partitioning_expression(const Oid relid,
575
576
quote_identifier (nspname ),
576
577
quote_identifier (relname ));
577
578
578
- parsetree_list = raw_parser (query_string );
579
+ old_mcxt = CurrentMemoryContext ;
580
+
581
+ PG_TRY ();
582
+ {
583
+ parsetree_list = raw_parser (query_string );
584
+ }
585
+ PG_CATCH ();
586
+ {
587
+ ErrorData * error ;
588
+
589
+ /* Switch to the original context & copy edata */
590
+ MemoryContextSwitchTo (old_mcxt );
591
+ error = CopyErrorData ();
592
+ FlushErrorState ();
593
+
594
+ error -> detail = error -> message ;
595
+ error -> message = "partitioning expression parse error" ;
596
+ error -> sqlerrcode = ERRCODE_INVALID_PARAMETER_VALUE ;
597
+ error -> cursorpos = 0 ;
598
+ error -> internalpos = 0 ;
599
+
600
+ ReThrowError (error );
601
+ }
602
+ PG_END_TRY ();
603
+
579
604
if (list_length (parsetree_list ) != 1 )
580
605
elog (ERROR , "expression \"%s\" produced more than one query" , exp_cstr );
581
606
@@ -660,8 +685,30 @@ cook_partitioning_expression(const Oid relid,
660
685
*/
661
686
old_mcxt = MemoryContextSwitchTo (parse_mcxt );
662
687
663
- /* This will fail with elog in case of wrong expression */
664
- querytree_list = pg_analyze_and_rewrite (parsetree , query_string , NULL , 0 );
688
+ PG_TRY ();
689
+ {
690
+ /* This will fail with elog in case of wrong expression */
691
+ querytree_list = pg_analyze_and_rewrite (parsetree , query_string , NULL , 0 );
692
+ }
693
+ PG_CATCH ();
694
+ {
695
+ ErrorData * error ;
696
+
697
+ /* Switch to the original context & copy edata */
698
+ MemoryContextSwitchTo (old_mcxt );
699
+ error = CopyErrorData ();
700
+ FlushErrorState ();
701
+
702
+ error -> detail = error -> message ;
703
+ error -> message = "partitioning expression analyze error" ;
704
+ error -> sqlerrcode = ERRCODE_INVALID_PARAMETER_VALUE ;
705
+ error -> cursorpos = 0 ;
706
+ error -> internalpos = 0 ;
707
+
708
+ ReThrowError (error );
709
+ }
710
+ PG_END_TRY ();
711
+
665
712
if (list_length (querytree_list ) != 1 )
666
713
elog (ERROR , "partitioning expression produced more than 1 query" );
667
714
0 commit comments