AW: BUG #17842: Adding a qual to a working query gets bogus syntax error - Mailing list pgsql-bugs

From Hans Buschmann
Subject AW: BUG #17842: Adding a qual to a working query gets bogus syntax error
Date
Msg-id dd6cfce2fca54079b1ad7cd044ee4b38@nidsa.net
Whole thread Raw
In response to Re: BUG #17842: Adding a qual to a working query gets bogus syntax error  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #17842: Adding a qual to a working query gets bogus syntax error  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs

Hello Tom,


thanks for the quick response.


You are probably right with your assumption of a not convertible substring, but some questions remain:


1. When the question runs succesfully, all lines are subject to the join of qj (newcol_imp and oldcol_imp heve exact the same number of lines, matching logically), but why does a limitation of the result set trigger the error?


(There really may be some substrings from declarations of numeric(4,1) which are not excluded properly from conversion to smallint.

The '0'||<rest> tries to handle an empty string)


2. Why is it reporting an syntax error (supposed at parse time) and not a runtime error (supposed at execution time)


3. Why does an uncorrelated qual like and onum < 100 trigger an error too? 

( I know that a limitation can change the choosen plan, but which one cannot be seen because of the error.)


The behavior of having a succesfull full query, but getting the error with some quals seems to me very unintuitive.


PS: The exactness and correctness of this specific query is certainly not overall important for me, but I wanted to point out this very unexpected behavior for some other users.


When I find some time, I'll try to provide some anonymized data.


Best regards


Hans Buschmann


Von: Tom Lane <tgl@sss.pgh.pa.us>
Gesendet: Dienstag, 14. März 2023 17:20
An: Hans Buschmann
Cc: pgsql-bugs@lists.postgresql.org
Betreff: Re: BUG #17842: Adding a qual to a working query gets bogus syntax error
 
PG Bug reporting form <noreply@postgresql.org> writes:
> During refactoring our application I got a bogus syntax error when adding a
> simple where-clause to a working query.

My guess is that this:

> ('0'||split_part(split_part(nline,'(',2),')',1))::smallint as nlen

sometimes produces a string that fails to cast to smallint, which you
accidentally don't notice because it never gets evaluated for troublesome
values of nline --- until you add the "nlen > 0" condition.  There isn't
anything in your query that prevents that from being evaluated fairly
early.

This isn't a bug, or at least you have provided no data that would
motivate (or indeed allow) anyone else to poke into it more closely.

                        regards, tom lane

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #17843: Writing uninitialised data in logtape/buffile
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #17842: Adding a qual to a working query gets bogus syntax error