【问题标题】:Whats meaning of where false; in SQL querywhere false 的含义是什么?在 SQL 查询中
【发布时间】:2018-03-06 02:32:41
【问题描述】:

我在sqitch db schema management tool中遇到了一个SQL查询,如下:

BEGIN;

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

ROLLBACK;

上面的查询是验证策略的一部分; where false; 在上述查询中的解释或应用是什么?

【问题讨论】:

    标签: sql database database-migration rdbms sqitch


    【解决方案1】:

    据我所知,这是为了让您始终获得 0 个结果。 与执行 where 1=0

    之类的操作相同

    【讨论】:

      【解决方案2】:

      当查询不应该返回任何结果时使用的 where 条件。 一些支持布尔值的 DBMS,例如 Postgres,被用来代替经典的 where 1=1

      基本上,where falsewhere 1=0 相同。

      【讨论】:

      • 所以它唯一的 postgres 特定命令?它会和mysql一起工作吗?
      • 我有机会在 Postgres 中使用它,但我猜任何支持布尔值的 DBMS 都应该可以使用该语法。
      • 刚刚在 MySQL 上尝试过,查询工作正常。我做了select * from table where false;,它没有返回任何值。然后我做了select * from table where true;,它返回了数据。
      • 不适用于 MS-SQL,因为存在 no boolean 数据类型
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多