在PostgreSQL中对AND和OR条件进行分组

编程入门 行业动态 更新时间:2024-10-27 16:35:52
本文介绍了在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条件进行分组

本文发布于:2023-10-22 22:43:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518945.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中对   条件   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!