Postgres RDBMS/Working with PostgreSQL

From Wikibooks, open books for an open world
Jump to: navigation, search

Data types[edit]

String types[edit]

Numeric types[edit]

Date and Time types[edit]

Network address data types[edit]

MACADDR
Represents a MAC address
INET
Represents an IP network or host. This includes an optional netmask. For example, 123.45.67.89 or 192.168.0.0/24
CIDR
Represents an IP network, with an optional netmask. For example, 192.168.0.0/24 or 192.168.0

User-defined types[edit]

Constraints[edit]

UNIQUE constraints[edit]

Primary key constraints[edit]

CHECK constraints[edit]

Managing a database[edit]

Clusters[edit]

Database[edit]

Each database is a separate collection of data. The only thing shared between databases is the list of users and groups. Each connection to the server must be to a single database, and cannot read or write data in any other database.

This is different to the way MySQL uses the term "database". A MySQL database is closer to PostgreSQL's concept of a schema.

You can create a new database from the SQL shell, with the command

CREATE DATABASE dbname;

Alternatively, you can create the database from the command line with the createdb script:

$ createdb dbname

createdb takes the same user authentication parameters as psql.

Tablespaces[edit]

Schemas[edit]

Users and Groups[edit]