Postgresql case and testing boolean fields Postgresql case and testing boolean fields postgresql postgresql

Postgresql case and testing boolean fields


Your problem is a mismatch in your values (expressions after then and else), not your predicate (expression after when). Make sure that select name from tableA and select name from tableB return the same result type. mycheck is supposed to be a boolean.

I ran this query on PostgreSQL 9.0beta2, and (except for having to add from mytable to the SELECT statement as well as creating tables tableA and tableB), and it didn't yield any type errors. However, I get an error message much like the one you described when I run the following:

select case when true           then 1           else 'hello'::text        end;

The above yields:

ERROR:  CASE types text and integer cannot be matched


I just ran this fine on PostgreSQL 8:

select id, case when mycheck = true then (...)      else (...), someText;