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 do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL with YAML?
- How do I store binary data in a Postgresql database using the bytea data type?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I rename a column in PostgreSQL?
- How can I use PostgreSQL's "zero if null" feature?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How can I extract the year from a PostgreSQL timestamp?
See more codes...