JhonDoe
JhonDoe

Reputation: 27

postgresql where conditional, mixin "AND" "OR"

I need to get the data from a DB and match two columns: Key and name, but I cant get it to work, if I use AND on both conditions:

...where lower(items.key_) SIMILAR TO lower('memory.size')
   and lower(items.name) SIMILAR TO lower('Memory Utilization%')
   and history.clock > '2020-08-12 03:05:32'

the query doesnt work because when items.key is similar to memory.size, items.name will never be similar to "Memory Utilization", so I try to do it with OR:

...where lower(items.key_) SIMILAR TO lower('memory.size')
   or lower(items.name) SIMILAR TO lower('Memory Utilization%')
   and history.clock > '2020-08-12 03:05:32'

But it doesnt work either.

Any Ideas?

Upvotes: 0

Views: 97

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269693

SIMILAR TO is not really the operator you want. You are using %, so that suggests LIKE:

where (lower(items.key_) like lower('memory.size') or
       lower(items.name) like lower('Memory Utilization%')
      ) and history.clock > '2020-08-12 03:05:32'

Upvotes: 2

Related Questions