2

I came across one SQL query in sqitch db schema management tool which is as follows:

BEGIN;

select subject , comment , timestamp
from tutorial.video
where false; 

ROLLBACK;

Above query is part of verify strategy; What is interpretation or application of where false; in above query?

Pramod S. Nikam
  • 4,271
  • 4
  • 38
  • 62

2 Answers2

3

It is a where condition to be used when the query should not return any result. Some DBMS supporting boolean values, Postgres for example, are used to work with that instead of the classic where 1=1.

Basically then, where false is the same of where 1=0.

P3trur0
  • 3,155
  • 1
  • 13
  • 27
  • so its only postgres specific command? Will it wirk with mysql? – Pramod S. Nikam Sep 25 '17 at 07:48
  • I had chance to use that just in Postgres, but any DBMS supporting boolean values should be fine with that syntax, I guess. – P3trur0 Sep 25 '17 at 07:50
  • 2
    Just tried on MySQL and the query works. I did `select * from table where false;` and it returns no values. Then I did `select * from table where true;` and it returns the data. – P3trur0 Sep 25 '17 at 07:55
  • 2
    Won't work with MS-SQL cause theres [no boolean](https://stackoverflow.com/questions/3138029/is-there-a-boolean-data-type-in-microsoft-sql-server-like-there-is-in-mysql) datatype – MatSnow Sep 25 '17 at 08:01
2

As far as I can tell it's to make you always get back 0 results. Same as doing something like where 1=0

Roee N
  • 502
  • 2
  • 4
  • 17