Jian Shi
Jian Shi
Aug 31, 2018 · 1 min read

Yes, you have to use ‘text’ type for using the PGP encryption. You may read this for more details.

Meanwhile, for you question, I do not think it is possible to do the SUM() operation natively on encrypted data. While the main problem is not the data type, Postgres is not able to get the original data, in your case is the balance number. Especially when the AES key is out of the control from Postgres.

Hence, the sum operation must be done out of the Postgres. I think one work around shall be: decryption -> sum() -> encryption. Sadly, I could imagine the slow process of it if too much data comes in.

    Jian Shi

    Written by

    Jian Shi