在PostgreSQL中对AND和OR条件进行分组 [英] Grouping AND and OR conditionals in PostgreSQL
本文介绍了在PostgreSQL中对AND和OR条件进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我总是在SQL查询中使用方括号.但是我有一个例子:
I always use brackets in sql queries. But I have example:
DELETE FROM prog
WHERE prog_start >= $1 AND prog_start < $2
OR prog_end > $1 AND prog_end <= $2
等于:
DELETE FROM prog
WHERE ( prog_start >= $1 AND prog_start < $2 )
OR ( prog_end > $1 AND prog_end <= $2 )
还是不?
推荐答案
在SQL中,AND
运算符比OR
运算符具有优先级". PostgreSQL遵守这里的规范.您可以在docs 词汇中确定PostgreSQL中的确切优先级.结构:运算符优先级.
In SQL the AND
operator takes "precedence" over OR
operator. PostgreSQL adheres to the spec here. You can the exact precedence in PostgreSQL in the docs Lexical Structure: Operator Precedence.
因此,在您的情况下,结果将是相同的.但是,简单地使用括号会更容易,更清洁.
So in your case, the result will be the same. However, it's much easier, and cleaner to simply use the parentheses.
这篇关于在PostgreSQL中对AND和OR条件进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文