# Part II. 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 seePart VI.

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 readPart Ifirst. SQL commands are typically entered using the PostgreSQL interactive terminal psql, but other programs that have similar functionality can be used as well.

Table of Contents

4. SQL Syntax

4.1. Lexical Structure

4.2. Value Expressions

4.3. Calling Functions

5. Data Definition

5.1. Table Basics

5.2. Default Values

5.3. Generated Columns

5.4. Constraints

5.5. System Columns

5.6. Modifying Tables

5.7. Privileges

5.8. Row Security Policies

5.9. Schemas

5.10. Inheritance

5.11. Table Partitioning

5.12. Foreign Data

5.13. Other Database Objects

5.14. Dependency Tracking

6. Data Manipulation

6.1. Inserting Data

6.2. Updating Data

6.3. Deleting Data

6.4. Returning Data from Modified Rows

7. Queries

7.1. Overview

7.2. Table Expressions

7.3. Select Lists

7.4. Combining Queries (UNION,INTERSECT,EXCEPT)

7.5. Sorting Rows (ORDER BY)

7.6.LIMITandOFFSET

7.7.VALUESLists

7.8.WITHQueries (Common Table Expressions)

8. Data Types

8.1.数值类型

8.2.货币类型

8.3.字符类型

8.4.二进制数据类型

8.5.日期/时间类型

8.6.布尔类型

8.7.枚举类型

8.8.几何类型

8.9.网络地址类型

8.10.位串类型

8.11.文本搜索类型

8.12.UUID 类型

8.13.XML 类型

8.14.JSON 类型

8.15.数组

8.16.复合类型

8.17.范围类型

8.18.域类型

8.19.对象标识符类型

8.20.pg_lsn类型

8.21.伪类型

9. 函数和运算符9.1.

逻辑运算符9.2.

比较函数和运算符9.3.

数学函数和运算符9.4.

字符串函数和运算符9.5.

二进制字符串函数和运算符

9.6.位串函数和运算符

9.7.模式匹配

9.8.数据类型格式化函数

9.9.日期/时间函数和运算符

9.10.枚举支持函数

9.11.几何函数和运算符

9.12.网络地址函数和运算符

9.13.文本搜索函数和运算符

9.14.UUID 函数

9.15.XML 函数

9.16.JSON 函数和运算符

9.17.序列操作函数

9.18.条件表达式

9.19.数组函数和运算符

9.20.范围/多范围函数和运算符

9.21.聚合函数

9.22.窗口函数

9.23.子查询表达式

9.24.行和数组比较

9.25.设置返回函数

9.26.系统信息函数和运算符

9.27.系统管理功能

9.28.触发函数

9.29.事件触发函数

9.30.统计信息功能

10. 类型转换10.1.

概述10.2.

运营商10.3.

职能

10.4. Value Storage

10.5.UNION,CASE, and Related Constructs

10.6.SELECTOutput Columns

11. Indexes

11.1. Introduction

11.2. Index Types

11.3. Multicolumn Indexes

11.4. Indexes andORDER BY

11.5. Combining Multiple Indexes

11.6. Unique Indexes

11.7. Indexes on Expressions

11.8. Partial Indexes

11.9. Index-Only Scans and Covering Indexes

11.10. Operator Classes and Operator Families

11.11. Indexes and Collations

11.12. Examining Index Usage

12. Full Text Search

12.1. Introduction

12.2. Tables and Indexes

12.3. Controlling Text Search

12.4. Additional Features

12.5. Parsers

12.6. Dictionaries

12.7. Configuration Example

12.8. Testing and Debugging Text Search

12.9. GIN and GiST Index Types

12.10. psql Support

12.11. Limitations

13. Concurrency Control

13.1. Introduction

13.2. Transaction Isolation

13.3. Explicit Locking

13.4. Data Consistency Checks at the Application Level

13.5. Caveats

13.6. Locking and Indexes

14. Performance Tips

14.1. UsingEXPLAIN

14.2. Statistics Used by the Planner

14.3. Controlling the Planner with ExplicitJOINClauses

14.4. Populating a Database

14.5. Non-Durable Settings

15. Parallel Query

15.1. How Parallel Query Works

15.2. When Can Parallel Query Be Used?

15.3. Parallel Plans

15.4. Parallel Safety