Skip site navigation (1) Skip section navigation (2)

Proposed patch for error locations

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-patches(at)postgreSQL(dot)org
Subject: Proposed patch for error locations
Date: 2006-03-12 17:37:35
Message-ID: 5114.1142185055@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-interfacespgsql-patches
The attached WIP patch improves the parser so that cursor positions can be
attached to many errors reported during parse analysis, such as complaints
about nonexistent columns or functions.  This is along the lines proposed
in my rant here:
http://archives.postgresql.org/pgsql-patches/2006-02/msg00234.php
to wit, that we make use of bison's "locations" feature to track token
positions in the grammar, and add locations to raw parse tree nodes as
needed.

Some examples of what it can do:

regression=# select unique1,unique2,tem,hundred from tenk1 t;
ERROR:  column "tem" does not exist at character 24
LINE 1: select unique1,unique2,tem,hundred from tenk1 t;
                               ^
regression=# select unique1+unique2,ten+hundred,thousand+stringu1 from tenk1;
ERROR:  operator does not exist: integer + name at character 44
HINT:  No operator matches the given name and argument type(s). You may need to add explicit type casts.
LINE 1: select unique1+unique2,ten+hundred,thousand+stringu1 from te...
                                                   ^

These examples are perhaps not all that exciting, but in a complex SQL
statement extending over dozens of lines I think it's really important
to be able to do this.

I haven't gone further than making it finger the locations of bogus column
references, operators, and functions --- it's probably worth improving
TypeCast and maybe a few other raw-parse-tree constructs too.  Another thing
that needs to be looked at is using the mechanism to locate statement
boundaries, which was the starting-point of the thread mentioned above.

One thing I'm noticing already is that the addition of "at character N"
to a lot of these messages isn't an improvement.  In psql it's certainly
redundant with the error-cursor display.  As I recall, we include that string
in the primary message text to improve usability with poorer application APIs
that might only show the primary error message to the user.  I'm thinking
maybe it's time to expect those client libraries to do better.  Any thoughts
about that?

Any comments in general?

			regards, tom lane


Attachment: error-position-1.patch.gz
Description: application/octet-stream (18.0 KB)

Responses

pgsql-patches by date

Next:From: Volkan YAZICIDate: 2006-03-12 17:59:10
Subject: Re: psql patch: new host/port without leaving session
Previous:From: Tatsuo IshiiDate: 2006-03-12 01:19:49
Subject: Re: [PATCHES] pg_freespacemap question

pgsql-interfaces by date

Next:From: Michael GlaesemannDate: 2006-03-13 07:42:59
Subject: Re: Proposed patch for error locations
Previous:From: Tom LaneDate: 2006-03-12 16:18:54
Subject: Re: Receiving SIGPIPE for PQfinish(<broken-connection>)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group