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 troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL with YAML?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I parse XML data using PostgreSQL?
- How do I set the PostgreSQL work_mem parameter?
- How do I use a PostgreSQL XML parser in an example?
- How can I convert XML data to a PostgreSQL table?
- How do I set up a web interface for PostgreSQL?
See more codes...