当用作谓词时,SQL 元组是否只是扩展逻辑与的语法糖?

Are SQL tuples, when used as predicates, just a syntactic sugar for expanded logical AND's?

当用作谓词时,SQL 元组只是扩展逻辑 AND 的语法糖还是还有更多?

例如

with tmp1(c1,c2,c3) as (
  select * from (
    values(1,'a','apple')
    ,(2,'b','ball')
    ,(3,'c','cat')
    ,(4,'d','dog')
    ,(5,'e',null)
  )
)
select * from tmp1 where (c1,c2,c3) = (1,'a','apple');

等同于

select * from tmp1 where c1 = 1 and c2 = 'a' and c3 = 'apple';

IN 子句或 JOIN 的类似情况

我确实检查了 NULL 意识(如果它会被翻译成 x IS NOT DISTINCT FROM y 的形式)但至少 DB2 不是

select * from tmp1 where (c1,c2,c3) = (5,'e',null); -- Empty resultset

当你严格考虑标量相等时,是的,它是等价的。

还有其他不那么简单的情况:

  • 当您考虑带有集合运算符的谓词时,如 INNOT IN 那么它是一个更强大的结构,如:

    (a, b, c) in (select x, y, z...)
    (a, b, c) not in (select x, y, z...)
    
  • 当谓词包含元组不等式。这在查询分页中特别有用。例如:

    (a, b, c) >= (x, y, z)
    

    如果没有元组,语法会更加冗长,如:

    a > x OR a = x AND (b > y OR b = y AND c >= z)