8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.111 2004/01/06 23:55:18 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.112 2004/03/14 01:58:41 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -44,6 +44,7 @@ Datum fmgr_sql_validator(PG_FUNCTION_ARGS);
44
44
45
45
static Datum create_parameternames_array (int parameterCount ,
46
46
const char * parameterNames []);
47
+ static void sql_function_parse_error_callback (void * arg );
47
48
48
49
49
50
/* ----------------------------------------------------------------
@@ -708,6 +709,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
708
709
bool isnull ;
709
710
Datum tmp ;
710
711
char * prosrc ;
712
+ ErrorContextCallback sqlerrcontext ;
711
713
char functyptype ;
712
714
bool haspolyarg ;
713
715
int i ;
@@ -760,6 +762,16 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
760
762
761
763
prosrc = DatumGetCString (DirectFunctionCall1 (textout , tmp ));
762
764
765
+ /*
766
+ * Setup error traceback support for ereport(). This is mostly
767
+ * so we can add context info that shows that a syntax-error
768
+ * location is inside the function body, not out in CREATE FUNCTION.
769
+ */
770
+ sqlerrcontext .callback = sql_function_parse_error_callback ;
771
+ sqlerrcontext .arg = proc ;
772
+ sqlerrcontext .previous = error_context_stack ;
773
+ error_context_stack = & sqlerrcontext ;
774
+
763
775
/*
764
776
* We can't do full prechecking of the function definition if there
765
777
* are any polymorphic input types, because actual datatypes of
@@ -778,9 +790,32 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
778
790
}
779
791
else
780
792
querytree_list = pg_parse_query (prosrc );
793
+
794
+ error_context_stack = sqlerrcontext .previous ;
781
795
}
782
796
783
797
ReleaseSysCache (tuple );
784
798
785
799
PG_RETURN_VOID ();
786
800
}
801
+
802
+ /*
803
+ * error context callback to let us supply a context marker
804
+ */
805
+ static void
806
+ sql_function_parse_error_callback (void * arg )
807
+ {
808
+ Form_pg_proc proc = (Form_pg_proc ) arg ;
809
+
810
+ /*
811
+ * XXX it'd be really nice to adjust the syntax error position to
812
+ * account for the offset from the start of the statement to the
813
+ * function body string, not to mention any quoting characters in
814
+ * the string, but I can't see any decent way to do that...
815
+ *
816
+ * In the meantime, put in a CONTEXT entry that can cue clients
817
+ * not to trust the syntax error position completely.
818
+ */
819
+ errcontext ("SQL function \"%s\"" ,
820
+ NameStr (proc -> proname ));
821
+ }
0 commit comments