How to cast varchar to boolean
问题 I have a variable 'x' which is varchar in staging table, but it is set to boolean in target table which has 'true' and 'false' values. How can I convert varchar to boolean in postgresql? 回答1: If the varchar column contains one of the strings (case-insensitive): t , true , y , yes , on , 1 f , false , n , no , off , 0 you can simply cast it to boolean, e.g: select 'true'::boolean, 'false'::boolean; bool | bool ------+------ t | f (1 row) See SQLFiddle. 回答2: For Redshift, I had the best luck