useless WHERE conditions

martin van dinther martin.van.dinther at monetdbsolutions.com
Fri Oct 17 13:44:33 CEST 2014


FYI: MonetDB SQL also accepts WHERE TRUE AND ...
  if you prefer that syntax instead of WHERE 1=1 AND ...

Also it supports columns of datatype BOOLEAN, so you can write SQL 
queries like:

create table person (name varchar(20) not null primary key, married 
boolean default false not null);
insert into person (name) values ('jan');
insert into person (name, married) values ('isabelle', true);
select name, married from person where TRUE;
select name, married from person where married;
select name, married from person where married = true;
select name, married from person where not married;


On 17-10-14 11:00, gms_xy at gmx.de wrote:
> To have a human-readable SQL code, I am used in following code formatting:
>
> SELECT
>      a
> FROM
>      tbl
> WHERE
>      1=1   --<<-- absolutely useless, but nice for formatting
>      AND col1 = 1
>      AND col2 = 2
>      AND col3 = 3
>
> Instead of "1=1", some other databases accept "TRUE". When I have multiple OR-conditions, I start with "1=0" or "FALSE". Writing statements this way I noticed long execution times in MonetDB. Omitting the logical where-condition "1=1" results in very fast execution time. So I guess, MonetDB is really checking on every row, if 1=1.




More information about the developers-list mailing list