Reporting errors inside plpgsql/SPI queries

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Reporting errors inside plpgsql/SPI queries
Date: 2004-03-21 17:53:33
Message-ID: 26433.1079891613@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I've been fooling with adding a report of the executing query to the
CONTEXT stack when an error happens within a query submitted by a
plpgsql function. Since plpgsql submits all its queries through SPI,
the most convenient place to do this is in spi.c, and so the behavior
will also apply to queries submitted via SPI by user-written C
functions.

What I've currently got labels the failing query as a "SPI query",
for example

regression=# create or replace function foo(text) returns text as $$
regression$# begin
regression$# execute 'select * from ' || $1;
regression$# return 'good';
regression$# end
regression$# $$ language plpgsql;
CREATE FUNCTION

regression=# select foo('int4_tbl');
foo
------
good
(1 row)

regression=# select foo('nosuch_tbl');
ERROR: relation "nosuch_tbl" does not exist
CONTEXT: SPI query "select * from nosuch_tbl"
PL/pgSQL function "foo" line 2 at execute statement

regression=# select foo('fee fie fo fum');
ERROR: syntax error at or near "fo" at character 23
CONTEXT: SPI query "select * from fee fie fo fum"
PL/pgSQL function "foo" line 2 at execute statement

Although this is quite reasonable for queries submitted by user-written
C functions, I'm worried that plpgsql programmers will be confused
because they've never heard of SPI. I toyed with saying "SQL query"
instead, but that seems pretty nearly content-free ... it doesn't
distinguish these queries from ones submitted directly by the client.
Can anyone think of a better wording? Does this bother people enough
to justify hacking the SPI interface to allow a label to be passed in?

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-03-21 18:11:49 Re: Syntax error reporting (was Re: [PATCHES] syntax error position "CREATE FUNCTION" bug fix)
Previous Message Arthur Ward 2004-03-21 17:48:26 Re: Unbalanced Btree Indices ...