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
Is it equal to :
DELETE FROM prog
WHERE ( prog_start >= $1 AND prog_start < $2 )
OR ( prog_end > $1 AND prog_end <= $2 )
or not ?
In PostgreSQL, the GROUPING SETS are used to generate a result set equivalent to which generated by the UNION ALL of the multiple GROUP BY clauses. A grouping set is a set of columns by which the user group. Typically, a single aggregate query defines a single grouping set.
Both GROUP BY and ORDER BY are clauses (or statements) that serve similar functions; that is to sort query results. However, each of these serve very different purposes; so different in fact, that they can be employed separately or together.
What Is Group By in SQL? The Group By statement is used to group together any rows of a column with the same value stored in them, based on a function specified in the statement. Generally, these functions are one of the aggregate functions such as MAX() and SUM().
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.
It goes as per the Operator Precendence http://www.postgresql.org/docs/6.5/static/operators.htm#AEN1615.
To form a complex condition it's always better to parenthesis your conditions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With