Having a hard time finding a good example of this is the docs. How would you sum all the values for a given key?
For example, I have a flight and duty log where users store times they have flown or worked. Since what keys are stored is kind of up to the user...I am storing these k/v pairs using hstore. One duty log will be created each day. If a user logs time in the same aircraft day after day...I need to be able to do something like this:
Dutylog.where(user_id: current_user).where("(properties -> '206B')::int > 0.0")
# properties is the hstore hash
This would find all the current users duty logs, then sum all the values where the key = "206B". The problem I am having in this example is type casting the string to an integer when the value should be a float. How do you type cast to a float?
Am I on the right track? How would you do this?
UPDATE
this gets the correct records...but, still working on how to sum that key/value
Dutylog.where("(properties -> '206B')::float > 1.1")