Defining boolean and temporal data columns

Creare database PostgreSQL

Darryl Reeves

Industry Assistant Professor, New York University

Boolean and temporal data

CREATE TABLE book (
    isbn CHAR(13) NOT NULL,
    author_first_name VARCHAR(50) NOT NULL,
    author_last_name VARCHAR(50) NOT NULL,
    content TEXT NOT NULL
);
Creare database PostgreSQL

Boolean and temporal data

CREATE TABLE book (
    isbn CHAR(13) NOT NULL,
    author_first_name VARCHAR(50) NOT NULL,
    author_last_name VARCHAR(50) NOT NULL,
    content TEXT NOT NULL,
    originally_published DATE NOT NULL,
    out_of_print BOOLEAN DEFAULT FALSE
);
Creare database PostgreSQL

The BOOLEAN data type

  • Three possible values
    • true state
    • false state
    • NULL (unknown state)
  • Common for representing yes-or-no scenarios
  • Can be defined with keyword BOOL or BOOLEAN
in_stock BOOL DEFAULT TRUE;
Creare database PostgreSQL

Temporal data types

Type Descriptions Format
TIMESTAMP represents a date and time 2010-09-21 15:47:16
DATE represents a date 1972-07-08
TIME represents a time 05:30:00
Creare database PostgreSQL

Let's practice!

Creare database PostgreSQL

Preparing Video For Download...