Re: debug_query_string and multiple statements

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Bruce Momjian <momjian(at)postgresql(dot)org>
Subject: Re: debug_query_string and multiple statements
Date: 2006-01-18 04:17:59
Message-ID: 4378.1137557879@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Neil Conway <neilc(at)samurai(dot)com> writes:
> While reviewing Joachim Wieland's patch to add a pg_cursors system view,
> I noticed that the patch assumes that debug_query_string contains the
> portion of the submitted query string that corresponds to the SQL
> statement we are currently executing. That is incorrect:

Yeah, this has annoyed me for some time. debug_query_string is really
just a quick hack and has already been stretched well past its intended
use. I don't think you get the right result for situations where the
active query has been submitted via SPI, either: debug_query_string will
show the outermost interactive command, which may have little to do with
the query that got the error.

The appropriate way to fix it IMHO is to get the lexer+grammar to
identify the statement boundary(s) in the source string and add explicit
support in the parser for saving away the appropriate strings.

This would tie nicely into something else I'd like to do someday, which
is improve parse-analysis error reports by being able to finger the
offending construct more precisely. When we report something like an
unknown variable name in a huge query, it really sucks that we can't
give an error cursor the way simple lexer or grammar errors do. To
fix that, tokens generated by the lexer/grammar need to carry along
text positions ... and the position of the semicolon token is just what
we'd need to create proper statement strings, too.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Fuhr 2006-01-18 04:27:58 Re: Error working with Temporary Sequences in plpgsql in 8.1 (8.0 works fine)
Previous Message Andrew Dunstan 2006-01-18 02:01:49 test please ignore