Just to address the storage angle in addition to what you posted as answer: boolean requires 1 byte on disk, smallint requires 2. If no assignment-grade cast is defined for the particular source and destination types, PL/pgSQL will fall back to its old I/O conversion behavior. 2 Answers Sorted by: 25 Always store boolean data as boolean. Other type conversions may succeed in more cases than before for example, assigning a numeric value 3.9 to an integer variable will now assign 4 rather than failing. Second, we converted 0 to October 1st 2015. This change causes conversions of Booleans to strings to produce true or false, not t or f. This example uses the CAST to convert a string to a date: SELECT CAST ( '' AS DATE ), CAST ( '0' AS DATE ) Code language: SQL (Structured Query Language) (sql) First, we converted literal string into January 1st 2015. Use assignment cast behavior for data type conversions in PL/pgSQL assignments, rather than converting to and from text (Tom Lane). ![]() If you want 0 and 1 instead, just cast the boolean to integer e.g. Some other RDBMS lack a proper implementation, which may add to the confusion. boolean is boolean and operates with a ternary logic around the values true, false and null. Same as Y and N in a char column.īoolean is neither binary nor a bitstring. OTOH t or f is a strong visual hint that we have a Boolean. Statistically 1 and 0 are often present as numbers so they would be harder to distinguish. ![]() ![]() If true as a value was returned that would be 4 times bigger than t, so that's not better. In PostgreSQL, I can cast individual boolean fields to integer when I want to get 0/1 output instead of f/t. TRUE and FALSE as cited in the question context are keywords, not values that can be returned to a client.
0 Comments
Leave a Reply. |