Re: IN clause behaving badly with missing comma and line break - Mailing list pgsql-bugs

From Philip Semanchuk
Subject Re: IN clause behaving badly with missing comma and line break
Date
Msg-id 1E97D89B-3195-4A55-918B-2C1152EEE497@americanefficient.com
Whole thread Raw
In response to IN clause behaving badly with missing comma and line break  (Roman Cervenak <roman@cervenak.info>)
Responses Re: IN clause behaving badly with missing comma and line break  (Francisco Olarte <folarte@peoplecall.com>)
List pgsql-bugs

> On Jan 18, 2023, at 2:51 AM, Roman Cervenak <roman@cervenak.info> wrote:
>
> Hello,
> if you use IN() clause (I've tested in WHERE and CASE) and you forget comma between values, it is syntax error
(correctbehaviour). But if there is newline between those two values, suddenly it is not syntax error (query will run
successfully),and all values are simply ignored.  
>
> Examples:
>
> WITH sample AS (SELECT 'c' AS t) SELECT CASE WHEN t IN ('a','b') THEN 1 WHEN t IN ('c'
>   'd') THEN 2 END FROM sample;
>
> WITH sample AS (SELECT 'c' AS t)
> SELECT * FROM sample WHERE t IN ('a'
> 'c’);


As David said, this is expected behavior, although it’s subtle and easy to overlook. We’ve adopted a formatting
standardthat helps us to avoid surprises due to missing commas. We put one string literal on each line and place the
commasall in the same column with a significant amount of white space to the left of the commas. With this safeguard in
place,it’s very easy to spot a missing comma. 

WHERE t IN ('a'      ,
            'foo'    ,
            'bar'    ,
            )


Cheers
Philip


pgsql-bugs by date:

Previous
From: Alex Richman
Date:
Subject: Re: Logical Replica ReorderBuffer Size Accounting Issues
Next
From: Francisco Olarte
Date:
Subject: Re: IN clause behaving badly with missing comma and line break