I am migrating a database from mysql to postgres. The migration itself was ok, following the postgres documentation.
Right now, I'm fixing our specific mysql queries.
In some point, we have now something like this:
select(%(
SUM(CASE WHEN income THEN value ELSE 0 END) AS rents,
SUM(CASE WHEN not income THEN value ELSE 0 END) AS expenses
))
In mysql, it was a sum(if(incomes, value, 0))
etc, and it was working as expected.
With PG, it returns a string instead of a numeric.
I already checked the database and the data type is correct.
What can I do, besides cast to_d
or to_f
?
EDIT: the complete query:
SELECT
SUM(CASE WHEN income THEN value ELSE 0 END) AS rents,
SUM(CASE WHEN not income THEN value ELSE 0 END) AS expenses
FROM "transactions"
WHERE "transactions"."type" IN ('Transaction')
AND "transactions"."user_id" = 1
AND "transactions"."paid" = 't'
AND (transactions.date between '2013-09-01' and '2013-09-30')
LIMIT 1