本文介绍了在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条件进行分组
发布评论