diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-21 22:29:11 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-21 22:29:11 +0000 |
commit | f938c2b91bebb7f436a3615cf86347d7261f71e8 (patch) | |
tree | 012d53c3414a88b0d35a4210becbcadf3b81a09c /src/backend/executor/functions.c | |
parent | bee3b2a0a01eab4b9e8d795fd2e3b5515bf22df3 (diff) | |
download | postgresql-f938c2b91bebb7f436a3615cf86347d7261f71e8.tar.gz postgresql-f938c2b91bebb7f436a3615cf86347d7261f71e8.zip |
Revise syntax-error reporting behavior to give pleasant results for
errors in internally-generated queries, such as those submitted by
plpgsql functions. Per recent discussions with Fabien Coelho.
Diffstat (limited to 'src/backend/executor/functions.c')
-rw-r--r-- | src/backend/executor/functions.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index 6ffc8875f19..8dec6131fb4 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.77 2004/01/07 18:56:26 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.78 2004/03/21 22:29:11 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -645,12 +645,40 @@ sql_exec_error_callback(void *arg) { FmgrInfo *flinfo = (FmgrInfo *) arg; SQLFunctionCachePtr fcache = (SQLFunctionCachePtr) flinfo->fn_extra; + HeapTuple func_tuple; + Form_pg_proc functup; char *fn_name; + int syntaxerrposition; - fn_name = get_func_name(flinfo->fn_oid); - /* safety check, shouldn't happen */ - if (fn_name == NULL) - return; + /* Need access to function's pg_proc tuple */ + func_tuple = SearchSysCache(PROCOID, + ObjectIdGetDatum(flinfo->fn_oid), + 0, 0, 0); + if (!HeapTupleIsValid(func_tuple)) + return; /* shouldn't happen */ + functup = (Form_pg_proc) GETSTRUCT(func_tuple); + fn_name = NameStr(functup->proname); + + /* + * If there is a syntax error position, convert to internal syntax error + */ + syntaxerrposition = geterrposition(); + if (syntaxerrposition > 0) + { + bool isnull; + Datum tmp; + char *prosrc; + + tmp = SysCacheGetAttr(PROCOID, func_tuple, Anum_pg_proc_prosrc, + &isnull); + if (isnull) + elog(ERROR, "null prosrc"); + prosrc = DatumGetCString(DirectFunctionCall1(textout, tmp)); + errposition(0); + internalerrposition(syntaxerrposition); + internalerrquery(prosrc); + pfree(prosrc); + } /* * Try to determine where in the function we failed. If there is a @@ -692,8 +720,7 @@ sql_exec_error_callback(void *arg) errcontext("SQL function \"%s\" during startup", fn_name); } - /* free result of get_func_name (in case this is only a notice) */ - pfree(fn_name); + ReleaseSysCache(func_tuple); } |