David Bentzon-Ehlers David Bentzon-Ehlers - 2 years ago 132
SQL Question

What is the SQL equivalent of COUNTIF?

I am trying to count the number of times a specific filter is used given its number of occurrences in a URL parameter. I have the URL parameter as a column. Here is a sample row result:

"lat"=>"28.5383355", "lng"=>"-81.37923649999999", "near"=>"Orlando, FL", "end_period"=>"05/08/2016", "place_input"=>"Orlando, Florida", "capacity_max"=>"100", "capacity_min"=>"7", "package_type"=>"bareboat", "start_period"=>"05/08/2016"

How would I go about counting the number of occurrences of e.g
? I tried using a wildcard, but SQL returned the following error message:

operator does not exist: hstore ~~ unknown
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 50

Hope somebody is able to help me out.

Answer Source

Use the operator hstore ? text which means does hstore contain key?

select count(*)
from a_table
where url ? 'lat';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download