Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL, problems with Boolean type storing values as "T" and "F" breaking ORM

If I define a boolean data type in a Postgres table and query from it, the results for the boolean columns come back as "t" or "f".

I'm using NPGSQL as my driver and Dapper as a ORM. This causes a problem because Dapper is unable to convert "t" or "f" into a boolean value, and all boolean values end up as False.

Is there a way to change this behavior with Postgres, or do I need to hack around it by using a character data type?

like image 346
Jonathan Holland Avatar asked Sep 10 '26 02:09

Jonathan Holland


1 Answers

Cast it to integer to get 0 or 1

SELECT boolean_value::INT ;

or to varchar to get 'true' or 'false'.

SELECT boolean_value::VARCHAR ;

Most DB drivers should be able to handle the one or the other.

like image 111
Mika Tähtinen Avatar answered Sep 12 '26 18:09

Mika Tähtinen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!