postgres.git / summary / log / commit / refs

commit    5d3fcc4c2e137417ef470d604fee5e452b22f6a7
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Tue Mar 27 19:17:00 2012 +0000
First released in: 9.2.0

    Bend parse location rules for the convenience of pg_stat_statements.
    
    Generally, the parse location assigned to a multiple-token construct is
    the location of its leftmost token.  This commit breaks that rule for
    the syntaxes TYPENAME 'LITERAL' and CAST(CONSTANT AS TYPENAME) --- the
    resulting Const will have the location of the literal string, not the
    typename or CAST keyword.  The cases where this matters are pretty thin on
    the ground (no error messages in the regression tests change, for example),
    and it's unlikely that any user would be confused anyway by an error cursor
    pointing at the literal.  But still it's less than consistent.  The reason
    for changing it is that contrib/pg_stat_statements wants to know the parse
    location of the original literal, and it was agreed that this is the least
    unpleasant way to preserve that information through parse analysis.
    
    Peter Geoghegan


src/backend/parser/parse_coerce.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index 6661a3d8a1d..3102f2089ec 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -280,13 +280,13 @@ coerce_type(ParseState *pstate, Node *node, newcon->constlen = typeLen(targetType); newcon->constbyval = typeByVal(targetType); newcon->constisnull = con->constisnull; - /* Use the leftmost of the constant's and coercion's locations */ - if (location < 0) - newcon->location = con->location; - else if (con->location >= 0 && con->location < location) - newcon->location = con->location; - else - newcon->location = location; + + /* + * We use the original literal's location regardless of the position + * of the coercion. This is a change from pre-9.2 behavior, meant to + * simplify life for pg_stat_statements. + */ + newcon->location = con->location; /* * Set up to point at the constant's text if the input routine throws [parent: a40fa613b516]