postgresqlHow do I use boolean values in PostgreSQL?
Boolean values are used in PostgreSQL to store true/false values. They are stored using the boolean data type.
Example code
CREATE TABLE test (
id serial PRIMARY KEY,
is_active boolean NOT NULL DEFAULT false
);
This code creates a table called test with an id column of type serial and a is_active column of type boolean. The is_active column is set to false by default.
To insert data into the table, use the INSERT command:
INSERT INTO test (is_active) VALUES (true);
This code inserts a row into the test table with the is_active column set to true.
To query the table, use the SELECT command:
SELECT * FROM test WHERE is_active = true;
This code returns all rows from the test table where the is_active column is set to true.
Helpful links
More of Postgresql
- How can I set a PostgreSQL interval to zero?
- How do I use PostgreSQL's ON CONFLICT DO NOTHING clause?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL XOR to compare two values?
- How do I set the PostgreSQL work_mem parameter?
- How can Zalando use PostgreSQL to improve its software development?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I monitor PostgreSQL performance using Zabbix?
See more codes...