

Postgresql cast as boolean code#
WHERE available Code language: SQL (Structured Query Language) ( sql ) For example, the following query returns all products that are available: SELECT * You can imply the true value by using the Boolean column without any operator. (5 rows) Code language: SQL (Structured Query Language) ( sql ) WHERE available = 'yes' Code language: SQL (Structured Query Language) ( sql ) product_id | available Third, use the following statement to check for the availability of products: SELECT * ( 800, '0') Code language: SQL (Structured Query Language) ( sql ) INSERT INTO stock_availability (product_id, available) We use various literal value for the boolean values. Second, insert some sample data into the stock_availability table. ) Code language: SQL (Structured Query Language) ( sql )

Let’s take a look at some examples of using the PostgreSQL Boolean data type.įirst, create a new table stock_availability to log which products are available. Note that the leading or trailing whitespace does not matter and all the constant values except for true and false must be enclosed in single quotes. The following table shows the valid literal values for TRUE and FALSE in PostgreSQL. However, PostgreSQL is quite flexible when dealing with TRUE and FALSE values. In standard SQL, a Boolean value can be TRUE, FALSE, or NULL. PostgreSQL uses one byte for storing a boolean value in the database. PostgreSQL supports a single Boolean data type: BOOLEAN that can have three values: true, false and NULL.
