Skip to content

Doing ActiveRecord Calculations Like Average On Encrypted Fields? #393

@dalezak

Description

@dalezak

Is it possible to do Rails calculations like average on encrypted fields?

Answer.average(:encrypted_value)

Or do you need to retrieve all values and then calculate the average in Ruby?

answers = Answer.all.map{|a| a.value.to_i}
answers.sum.to_f / answers.size.to_f

This obviously isn't very efficient so wondering if there's a better option.

Should I consider dropping the encryption? Any guidance would be greatly appreciated! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions