On Mon, Dec 11, 2017 at 3:52 PM, Tom Lane <t...@sss.pgh.pa.us> wrote: > Here's a quick hack at that. I guess the main question that needs to be > asked is whether we're happy with plpgsql getting so much chattier > (as per all the regression test changes). > > If we're not, the alternative that could be considered is to make SPI > expose some way to suppress its use of a context callback, and change > plpgsql to invoke that when dealing with an expression. That would > be rather more invasive code-wise, but would largely eliminate the > behavioral change as seen by users. > > Another angle, if we do keep it like this, is that maybe SPI should > export _SPI_error_callback so that plpgsql can use it directly, > rather than having a copy that needs to be kept in sync.
I confess to never having really grokked, even in the pre-patch state, why we sometimes get an "SQL statement" context line and sometimes not. However, what strikes me about this is that the SQL statement is a completely fabricated one that the user never entered. Consider this bit from the existing regression test output, unpatched: create function namedparmcursor_test7() returns void as $$ declare c1 cursor (p1 int, p2 int) for select * from tenk1 where thousand = p1 and tenthous = p2; begin open c1 (p2 := 77, p1 := 42/0); end $$ language plpgsql; select namedparmcursor_test7(); ERROR: division by zero CONTEXT: SQL statement "SELECT 42/0 AS p1, 77 AS p2;" PL/pgSQL function namedparmcursor_test7() line 6 at OPEN Quite obviously, nothing like "SELECT 42/0 AS p1, 77 AS p2;" is present in there anywhere. When people see an SQL statement in the context, or at least when I see it, my inclination is to go grep for where that SQL statement is to be found, and to be unhappy when the answer is nowhere. It would really be a lot better if we could say something like CONTEXT: SQL expression 42/0 ...but I realize that's probably hard to do. However, the current situation is that plpgsql.out contains 5 "SQL statement" context lines, of which only 1 is an SQL statement that actually appears in the procedure. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company