Creating PostgreSQL Databases
Darryl Reeves
Industry Assistant Professor, New York University
CREATE TABLE people.employee {
id SERIAL PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL
}
CREATE TABLE people.employee {
id SERIAL PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
num_sales INTEGER
}
Type | Description | Range |
---|---|---|
SMALLINT |
small-range integer | -32768 to +32767 |
Type | Description | Range |
---|---|---|
SMALLINT |
small-range integer | -32768 to +32767 |
INTEGER |
typical choice for integer | -2147483648 to +2147483647 |
Type | Description | Range |
---|---|---|
SMALLINT |
small-range integer | -32768 to +32767 |
INTEGER |
typical choice for integer | -2147483648 to +2147483647 |
BIGINT |
large-range integer | -9223372036854775808 to 9223372036854775807 |
Type | Description | Range |
---|---|---|
SMALLINT |
small-range integer | -32768 to +32767 |
INTEGER |
typical choice for integer | -2147483648 to +2147483647 |
BIGINT |
large-range integer | -9223372036854775808 to 9223372036854775807 |
SERIAL |
autoincrementing integer | 1 to 2147483647 |
Type | Description | Range |
---|---|---|
SERIAL |
autoincrementing integer | 1 to 2147483647 |
BIGSERIAL |
large autoincrementing integer | 1 to 9223372036854775807 |
CREATE TABLE people.employee {
id SERIAL PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
num_sales INTEGER
}
CREATE TABLE people.employee {
id SERIAL PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
num_sales INTEGER,
salary DECIMAL(8,2) NOT NULL
}
DECIMAL (precision, scale)
Type | Description | Range |
---|---|---|
DECIMAL or NUMERIC |
user-specified precision | 131072 digits before the decimal point;16383 digits after the decimal point |
Type | Description | Range |
---|---|---|
DECIMAL (NUMERIC ) |
user-specified precision | up to 131072 digits before the decimal point; up to 16383 digits after the decimal point |
REAL |
variable-precision | 6 decimal digits precision |
Type | Description | Range |
---|---|---|
DECIMAL (NUMERIC ) |
user-specified precision | up to 131072 digits before the decimal point; up to 16383 digits after the decimal point |
REAL |
variable-precision | 6 decimal digits precision |
DOUBLE PRECISION |
variable precision | 15 decimal digits precision |
Creating PostgreSQL Databases