Red Hat Database

SQL Guide and Reference


Table of Contents
1. SQL Syntax
Lexical Structure
Identifiers and Key Words
Constants
Operators and Special Characters
Comments
Lexical Precedence
Columns
Arrays
Value Expressions
Column References
Positional Parameters
Function Calls
Aggregate Expressions
Queries
Table Expressions
Select Lists
Sorting Rows
LIMIT and OFFSET
Combining Queries
Indices
Introduction to Indices
Index Types
Multi-Column Indices
Unique Indices
Functional Indices
Operator Classes
Keys
Partial Indices
Inheritance
2. Data Types
Numeric Types
The Serial Type
Monetary Type
Character Types
Date/Time Types
Date/Time Input
Date/Time Output
Date/Time Calculations
Boolean Type
Geometric Types
Point
Line Segment
Box
Path
Polygon
Circle
Network Address Data Types
inet
cidr
inet versus cidr
macaddr
Bit String Types
Large Objects (LOBs)
Type Conversion
Overview
Operators
Functions
Query Targets
UNION and CASE Constructs
3. Operators and Functions
Logical Operators
Comparison Operators
Mathematical Functions and Operators
Aggregate Functions
String Functions and Operators
Pattern Matching
Pattern Matching with LIKE
POSIX Regular Expressions
Formatting Functions
Date/Time Functions
EXTRACT
date_part
date_trunc
Current Date/Time
Geometric Functions and Operators
Network Address Type Functions
Large Object Functions
Miscellaneous Functions
4. Extending SQL
Background on Extensibility and Types
How Extensibility Works
The PostgreSQL Type System
Functions
Query Language (SQL) Functions
Procedural Language Functions
Compiled (C) Language Functions
Internal Functions
Triggers
User-Defined Types
Types and TOAST Tables
Array Types
Operators
Example
Operator Optimization Information
Indices and User-Defined Types
Aggregates
I. SQL Commands
5. Reference
ABORT --  Aborts the current transaction
ALTER GROUP --  Add users to a group, remove users from a group
ALTER TABLE --  Modifies table properties
ALTER USER --  Modifies user account information
BEGIN --  Begins a transaction in chained mode
CHECKPOINT -- Force transaction log checkpoint
CLOSE --  Close a cursor
CLUSTER --  Gives storage clustering advice to the server
COMMENT --  Add comment to an object
COMMIT --  Commits the current transaction
COPY --  Copies data between files and tables
CREATE AGGREGATE --  Defines a new aggregate function
CREATE CONSTRAINT TRIGGER --  Create a trigger to support a constraint
CREATE DATABASE --  Creates a new database
CREATE FUNCTION --  Defines a new function
CREATE GROUP --  Creates a new group
CREATE INDEX --  Constructs a secondary index
CREATE LANGUAGE --  Defines a new language for functions
CREATE OPERATOR --  Defines a new user operator
CREATE RULE --  Defines a new rule
CREATE SEQUENCE --  Creates a new sequence number generator
CREATE TABLE --  Creates a new table
CREATE TABLE AS --  Creates a new table from the results of a SELECT
CREATE TRIGGER --  Creates a new trigger
CREATE TYPE --  Defines a new base data type
CREATE USER --  Creates a new database user
CREATE VIEW --  Constructs a virtual table
DECLARE --  Defines a cursor for table access
DELETE --  Removes rows from a table
DROP AGGREGATE --  Removes the definition of an aggregate function
DROP DATABASE --  Removes an existing database
DROP FUNCTION --  Removes a user-defined C function
DROP GROUP --  Removes a group
DROP INDEX --  Removes existing indexes from a database
DROP LANGUAGE --  Removes a user-defined procedural language
DROP OPERATOR --  Removes an operator from the database
DROP RULE --  Removes existing rules from the database
DROP SEQUENCE --  Removes existing sequences from a database
DROP TABLE --  Removes existing tables from a database
DROP TRIGGER --  Removes an existing trigger
DROP TYPE --  Removes user-defined types from the system catalogs
DROP USER --  Removes a user
DROP VIEW --  Removes existing views from a database
END --  Commits the current transaction
EXPLAIN --  Shows statement execution plan
FETCH --  Gets rows using a cursor
GRANT --  Grants access privilege to a specific user, a specific group of users, or all users
INSERT --  Inserts new rows into a table
LISTEN --  Listen for a response on a notify condition
LOAD --  Dynamically loads an object file
LOCK --  Explicitly lock a table inside a transaction
MOVE --  Moves cursor position
NOTIFY --  Signals all frontends and backends listening on a notify condition
REINDEX --  Recover corrupted system indexes under stand-alone PostgreSQL
RESET -- Restores run-time parameters to default values
REVOKE --  Revokes access privilege from a specific user, a group of users, or all users.
ROLLBACK --  Aborts the current transaction
SELECT --  Retrieves rows from a table or view
SET -- Set run-time parameters
SET CONSTRAINTS -- Set the constraint mode of the current SQL transaction
SET TRANSACTION -- Set the characteristics of the current SQL-transaction
SHOW -- Shows run-time parameters
TRUNCATE --  Empty a table
UNLISTEN --  Stop listening for notification
UPDATE --  Replaces values of columns in a table
VACUUM --  Clean and analyze a PostgreSQL database
A. SQL Key Words
Index
SQL Guide and Reference