6

I can't believe that the following statement seems to be still true

So, I switched to integers and 0 or 1 works fine, but it is
stupid, that the database system has boolean variables of a smaller
size, but I should use integers for boolean values!

How do you use boolean datatype with Postgres / PHP?

In other words,

Is the only way to use 1 for true and 0 for false in getting the kind of the boolean datatype?

1 Answer 1

0

Using 1 and 0 is a very sensible and portable way to represent boolean values. Any difference in size between and int and a native boolean type is really going to make little or no difference to your application's performance, or the KB size of your database.

Sign up to request clarification or add additional context in comments.

4 Comments

Your answer suggests me that I need to change every datatype BOOLEAN in my SQL queries to INTEGER. It is strange that the BOOLEAN is made string by postgres after running the queries.
I wasn't suggesting that you change anything. Maybe out of habit or personal preference, I tend to use 0 & 1s to represent booleans. If that is already working for you, don't spend too much time thinking about it.
Figures are easy. Let's use them :)
Mysql actually uses 0 and 1 in a tinyint(1) when you define a boolean datatype.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.