2 Part II. The SQL Language
4 This part describes the use of the SQL language in PostgreSQL. We start
5 with describing the general syntax of SQL, then how to create tables,
6 how to populate the database, and how to query it. The middle part
7 lists the available data types and functions for use in SQL commands.
8 Lastly, we address several aspects of importance for tuning a database.
10 The information is arranged so that a novice user can follow it from
11 start to end and gain a full understanding of the topics without having
12 to refer forward too many times. The chapters are intended to be
13 self-contained, so that advanced users can read the chapters
14 individually as they choose. The information is presented in narrative
15 form with topical units. Readers looking for a complete description of
16 a particular command are encouraged to review the Part VI.
18 Readers should know how to connect to a PostgreSQL database and issue
19 SQL commands. Readers that are unfamiliar with these issues are
20 encouraged to read Part I first. SQL commands are typically entered
21 using the PostgreSQL interactive terminal psql, but other programs that
22 have similar functionality can be used as well.
28 4.1. Lexical Structure
29 4.2. Value Expressions
30 4.3. Calling Functions
37 5.4. Generated Columns
42 5.9. Row Security Policies
45 5.12. Table Partitioning
47 5.14. Other Database Objects
48 5.15. Dependency Tracking
55 6.4. Returning Data from Modified Rows
60 7.2. Table Expressions
62 7.4. Combining Queries (UNION, INTERSECT, EXCEPT)
63 7.5. Sorting Rows (ORDER BY)
66 7.8. WITH Queries (Common Table Expressions)
73 8.4. Binary Data Types
78 8.9. Network Address Types
79 8.10. Bit String Types
80 8.11. Text Search Types
88 8.19. Object Identifier Types
92 9. Functions and Operators
94 9.1. Logical Operators
95 9.2. Comparison Functions and Operators
96 9.3. Mathematical Functions and Operators
97 9.4. String Functions and Operators
98 9.5. Binary String Functions and Operators
99 9.6. Bit String Functions and Operators
100 9.7. Pattern Matching
101 9.8. Data Type Formatting Functions
102 9.9. Date/Time Functions and Operators
103 9.10. Enum Support Functions
104 9.11. Geometric Functions and Operators
105 9.12. Network Address Functions and Operators
106 9.13. Text Search Functions and Operators
109 9.16. JSON Functions and Operators
110 9.17. Sequence Manipulation Functions
111 9.18. Conditional Expressions
112 9.19. Array Functions and Operators
113 9.20. Range/Multirange Functions and Operators
114 9.21. Aggregate Functions
115 9.22. Window Functions
116 9.23. Merge Support Functions
117 9.24. Subquery Expressions
118 9.25. Row and Array Comparisons
119 9.26. Set Returning Functions
120 9.27. System Information Functions and Operators
121 9.28. System Administration Functions
122 9.29. Trigger Functions
123 9.30. Event Trigger Functions
124 9.31. Statistics Information Functions
132 10.5. UNION, CASE, and Related Constructs
133 10.6. SELECT Output Columns
139 11.3. Multicolumn Indexes
140 11.4. Indexes and ORDER BY
141 11.5. Combining Multiple Indexes
143 11.7. Indexes on Expressions
144 11.8. Partial Indexes
145 11.9. Index-Only Scans and Covering Indexes
146 11.10. Operator Classes and Operator Families
147 11.11. Indexes and Collations
148 11.12. Examining Index Usage
153 12.2. Tables and Indexes
154 12.3. Controlling Text Search
155 12.4. Additional Features
158 12.7. Configuration Example
159 12.8. Testing and Debugging Text Search
160 12.9. Preferred Index Types for Text Search
164 13. Concurrency Control
167 13.2. Transaction Isolation
168 13.3. Explicit Locking
169 13.4. Data Consistency Checks at the Application Level
170 13.5. Serialization Failure Handling
172 13.7. Locking and Indexes
177 14.2. Statistics Used by the Planner
178 14.3. Controlling the Planner with Explicit JOIN Clauses
179 14.4. Populating a Database
180 14.5. Non-Durable Settings
184 15.1. How Parallel Query Works
185 15.2. When Can Parallel Query Be Used?
187 15.4. Parallel Safety