squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

[BUG] Missing brackets when using several sq.Eq inside sq.Or

Open lobocv opened this issue 5 years ago • 2 comments

Hi there, I am trying to do the exact same thing that is shown in the FAQs https://github.com/Masterminds/squirrel#faq

      var metricMatcher =sq.Or{
		sq.Eq{"col1": 1, "col2": 2},
		sq.Eq{"col1": 3, "col2": 4}}

	psql := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)
	q := psql.Select("name", "SUM(col1) AS totals").From(tableName).Where(metricMatcher).GroupBy("col1")

The FAQs says the query should come out as:

WHERE (col1 = 1 AND col2 = 2) OR (col1 = 3 AND col2 = 4)

But I am getting

WHERE (col1 = 1 AND col2 = 2 OR col1 = 3 AND col2 = 4)

Note that they are all being put in the same bracket. Am I passing the sq.Or into the Where incorrectly?

lobocv avatar Dec 11 '20 20:12 lobocv

The documentation could be more assertive, but those two results are logically the same and should produce the same result

dcruzin avatar Dec 18 '20 12:12 dcruzin

I don't see how they are logically the same? Is there some BEDMAS like rules applied to logical conditions? Do AND's always resolve first before OR's?

lobocv avatar Dec 22 '20 20:12 lobocv