Defining boolean and temporal data columns

Creating PostgreSQL Databases

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
);
Creating PostgreSQL Databases

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
);
Creating PostgreSQL Databases

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;
Creating PostgreSQL Databases

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
Creating PostgreSQL Databases

Let's practice!

Creating PostgreSQL Databases

Preparing Video For Download...