I have a query like:
SELECT (column LIKE 'string')+100
It returns ERROR: operator does not exist: boolean + integer
I couldn't find a function to convert bool to int, there is only text to int: to_number().
Is there a way to resolve this issue?
Use Conditional Expressions, see http://www.postgresql.org/docs/9.2/static/functions-conditional.html
If you want to convert a string comparison to 1 when true and 0 when false, you could use a case statement:
select case when column like '%foo%' then 1 else 0 end as my_int from my_table;
If you wanted to add to that result, you would do something like:
select (case when column like '%foo%' then 1 else 0 end) + 100 as my_int from my_table;
SELECT (column LIKE 'string')::integer +100
trueor booleanfalseto be casted as?CASE WHEN .. THEN