Introduction to Relational Databases in SQL
Timo Grossenbacher
Data Journalist
text
: character strings of any lengthvarchar [ (x) ]
: a maximum of x
characters char [ (x) ]
: a fixed-length string of x
characters boolean
: can only take three states, e.g. TRUE
, FALSE
and NULL
(unknown)From the PostgreSQL documentation.
date
, time
and timestamp
: various formats for date and time calculationsnumeric
: arbitrary precision numbers, e.g. 3.1457
integer
: whole numbers in the range of -2147483648
and +2147483647
From the PostgreSQL documentation.
CREATE TABLE students (
ssn integer,
name varchar(64),
dob date,
average_grade numeric(3, 2), -- e.g. 5.54
tuition_paid boolean
);
ALTER TABLE students
ALTER COLUMN name
TYPE varchar(128);
ALTER TABLE students
ALTER COLUMN average_grade
TYPE integer
-- Turns 5.54 into 6, not 5, before type conversion
USING ROUND(average_grade);
Introduction to Relational Databases in SQL