Re: Suspected bug: outer WHERE reordered before inner WHERE -> input syntax ERROR - Mailing list pgsql-general

From Tom Lane
Subject Re: Suspected bug: outer WHERE reordered before inner WHERE -> input syntax ERROR
Date
Msg-id 2204.1220896383@sss.pgh.pa.us
Whole thread Raw
In response to Suspected bug: outer WHERE reordered before inner WHERE -> input syntax ERROR  (John Keith Hohm <john@hohm.net>)
Responses Re: Suspected bug: outer WHERE reordered before inner WHERE -> input syntax ERROR  (John Keith Hohm <john@hohm.net>)
Re: Suspected bug: outer WHERE reordered before inner WHERE -> input syntax ERROR  (Sam Mason <sam@samason.me.uk>)
List pgsql-general
John Keith Hohm <john@hohm.net> writes:
> This fails with ERROR:  invalid input syntax for integer: "JOHN":
> select * from (
>   select * from (VALUES ('100'), ('JOHN')) as A (n)
>   where trim(trim(n), '0123456789') = ''
> ) as B where n::integer <> -1;

This isn't a bug: the optimizer is entitled to rearrange WHERE clauses
any way it pleases.  If you want an optimization fence between the inner
and outer SELECTS, add OFFSET 0 (or LIMIT ALL if you like).

> I'm also interested in responses of the form "why not just do X?".

It does raise the question of why you aren't just doing
    where trim(n) != '-1'
I'm also wondering whether the logic is even consistent: something
with a minus sign in it will never get through the inner WHERE,
so what is the point of the outer one?

            regards, tom lane

pgsql-general by date:

Previous
From: "Markova, Nina"
Date:
Subject: How to check what is current postgres version
Next
From: justin
Date:
Subject: Re: How to check what is current postgres version