Search code examples
sqlinformixshort-circuiting

Short circuiting in Informix SQL


Does Informix support short circuiting in SQL clause? For example:

SELECT * FROM myTable
WHERE '0' IN (listOfValues) OR myTable.code IN (listOfValues) 

where listOfValues is a list of codes specified by the user (where '0' means all codes).

Many thanks!


Solution

  • Well, yes and no.

    It depends on how you construct listOfValues. You cannot use a ? placeholder for a list variable, but you can indeed write that SQL out long-hand and it will parse and do what you want. And you can call it short-circuiting if you wish.

    SELECT * FROM myTable
    WHERE '0' IN ('0') OR myTable.code IN ('0')
    

    will do what you require. But preparing

    SELECT * FROM myTable
    WHERE '0' IN (?) OR myTable.code IN (?)
    

    and executing it with bind variables that point to lists will produce a run-time error.

    All the usual caveats about why you should use bind variables still apply, you'll just need to find some other way to untaint (validate) your inputs.