4. The SQL Language
This part describes the use of the SQL language in PostgreSQL. We start with describing the general syntax of SQL, then explain how to create the structures to hold data, how to populate the database, and how to query it. The middle part lists the available data types and functions for use in SQL commands. The rest treats several aspects that are important for tuning a database for optimal performance.
The information in this part is arranged so that a novice user can follow it start to end to gain a full understanding of the topics without having to refer forward too many times. The chapters are intended to be self-contained, so that advanced users can read the chapters individually as they choose. The information in this part is presented in a narrative fashion in topical units. Readers looking for a complete description of a particular command should see reference.
Readers of this part should know how to connect to a PostgreSQL database and issue SQL commands. Readers that are unfamiliar with these issues are encouraged to read tutorial first. SQL commands are typically entered using the PostgreSQL interactive terminal psql, but other programs that have similar functionality can be used as well.
- 4.1. SQL Syntax
- 4.1.1. Lexical Structure
- 4.1.2. Value Expressions
- 4.1.2.1. Column References
- 4.1.2.2. Positional Parameters
- 4.1.2.3. Subscripts
- 4.1.2.4. Field Selection
- 4.1.2.5. Operator Invocations
- 4.1.2.6. Function Calls
- 4.1.2.7. Aggregate Expressions
- 4.1.2.8. Window Function Calls
- 4.1.2.9. Type Casts
- 4.1.2.10. Collation Expressions
- 4.1.2.11. Scalar Subqueries
- 4.1.2.12. Array Constructors
- 4.1.2.13. Row Constructors
- 4.1.2.14. Expression Evaluation Rules
- 4.1.3. Calling Functions
- 4.2. Data Definition
- 4.2.1. Table Basics
- 4.2.2. Default Values
- 4.2.3. Generated Columns
- 4.2.4. Constraints
- 4.2.5. System Columns
- 4.2.6. Modifying Tables
- 4.2.7. Privileges
- 4.2.8. Row Security Policies
- 4.2.9. Schemas
- 4.2.10. Inheritance
- 4.2.11. Table Partitioning
- 4.2.12. Foreign Data
- 4.2.13. Other Database Objects
- 4.2.14. Dependency Tracking
- 4.3. Data Manipulation
- 4.4. Queries
- 4.5. Data Types
- 4.5.1. Numeric Types
- 4.5.2. Monetary Types
- 4.5.3. Character Types
- 4.5.4. Binary Data Types
- 4.5.5. Date/Time Types
- 4.5.6. Boolean Type
- 4.5.7. Enumerated Types
- 4.5.8. Geometric Types
- 4.5.9. Network Address Types
- 4.5.10. Bit String Types
- 4.5.11. Text Search Types
- 4.5.12. UUID Type
- 4.5.13. XML Type
- 4.5.14. Domain Types
- 4.5.15. Object Identifier Types
- 4.5.16. pg_lsn Type
- 4.5.17. Pseudo-Types
- 4.6. Functions and Operators
- 4.6.1. Logical Operators
- 4.6.2. Comparison Functions and Operators
- 4.6.3. Mathematical Functions and Operators
- 4.6.4. String Functions and Operators
- 4.6.5. Binary String Functions and Operators
- 4.6.6. Bit String Functions and Operators
- 4.6.7. Pattern Matching
- 4.6.8. Data Type Formatting Functions
- 4.6.9. Date/Time Functions and Operators
- 4.6.10. Enum Support Functions
- 4.6.11. Geometric Functions and Operators
- 4.6.12. Network Address Functions and Operators
- 4.6.13. Text Search Functions and Operators
- 4.6.14. UUID Functions
- 4.6.15. XML Functions
- 4.6.16. JSON Functions and Operators
- 4.6.17. Sequence Manipulation Functions
- 4.6.18. Conditional Expressions
- 4.6.19. Array Functions and Operators
- 4.6.20. Range/Multirange Functions and Operators
- 4.6.21. Aggregate Functions
- 4.6.22. Window Functions
- 4.6.23. Subquery Expressions
- 4.6.24. Row and Array Comparisons
- 4.6.25. Set Returning Functions
- 4.6.26. System Information Functions and Operators
- 4.6.27. System Administration Functions
- 4.6.27.1. Configuration Settings Functions
- 4.6.27.2. Server Signaling Functions
- 4.6.27.3. Backup Control Functions
- 4.6.27.4. Recovery Control Functions
- 4.6.27.5. Snapshot Synchronization Functions
- 4.6.27.6. Replication Management Functions
- 4.6.27.7. Database Object Management Functions
- 4.6.27.8. Index Maintenance Functions
- 4.6.27.9. Generic File Access Functions
- 4.6.27.10. Advisory Lock Functions
- 4.6.28. Trigger Functions
- 4.6.29. Event Trigger Functions
- 4.6.30. Statistics Information Functions
- 4.7. Type Conversion
- 4.8. Indexes
- 4.8.1. Introduction
- 4.8.2. Index Types
- 4.8.3. Multicolumn Indexes
- 4.8.4. Indexes and ORDER BY
- 4.8.5. Combining Multiple Indexes
- 4.8.6. Unique Indexes
- 4.8.7. Indexes on Expressions
- 4.8.8. Partial Indexes
- 4.8.9. Index-Only Scans and Covering Indexes
- 4.8.10. Operator Classes and Operator Families
- 4.8.11. Indexes and Collations
- 4.8.12. Examining Index Usage
- 4.9. Full Text Search
- 4.10. Concurrency Control
- 4.11. Performance Tips
- 4.11.1. Using EXPLAIN
- 4.11.2. Statistics Used by the Planner
- 4.11.3. Controlling the Planner with Explicit JOIN Clauses
- 4.11.4. Populating a Database
- 4.11.4.1. Disable Autocommit
- 4.11.4.2. Use COPY
- 4.11.4.3. Remove Indexes
- 4.11.4.4. Remove Foreign Key Constraints
- 4.11.4.5. Increase maintenance_work_mem
- 4.11.4.6. Increase max_wal_size
- 4.11.4.7. Disable WAL Archival and Streaming Replication
- 4.11.4.8. Run ANALYZE Afterwards
- 4.11.4.9. Some Notes about pg_dump
- 4.11.5. Non-Durable Settings
- 4.12. Parallel Query