Part II. The SQL Language

This part describes the use of the SQL language in LightDB. 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 Part VI.

Readers of this part should know how to connect to a LightDB database and issue SQL commands. Readers that are unfamiliar with these issues are encouraged to read Part I first. SQL commands are typically entered using the LightDB interactive terminal ltsql, but other programs that have similar functionality can be used as well.

Table of Contents

5. SQL Syntax
5.1. Lexical Structure
5.2. Value Expressions
5.3. Calling Functions
6. Data Definition
6.1. Table Basics
6.2. Default Values
6.3. Generated Columns
6.4. Constraints
6.5. System Columns
6.6. Modifying Tables
6.7. Privileges
6.8. Row Security Policies
6.9. Schemas
6.10. Inheritance
6.11. Table Partitioning
6.12. Foreign Data
6.13. Other Database Objects
6.14. Dependency Tracking
6.15. LightDB DDL Specification Check
7. Data Manipulation
7.1. Inserting Data
7.2. Updating Data
7.3. Deleting Data
7.4. Returning Data from Modified Rows
7.5. LightDB DML Specification Check
8. Queries
8.1. Overview
8.2. Table Expressions
8.3. Select Lists
8.4. Combining Queries
8.5. Sorting Rows
8.6. LIMIT and OFFSET
8.7. VALUES Lists
8.8. WITH Queries (Common Table Expressions)
8.9. ROWNUM
8.10. Oracle Compatible Queries
8.11. MySQL Compatible Queries
9. Data Types
9.1. Numeric Types
9.2. Character Types
9.3. Binary Data Types
9.4. Date/Time Types
9.5. Boolean Type
9.6. Enumerated Types
9.7. Network Address Types
9.8. Bit String Types
9.9. Text Search Types
9.10. UUID Type
9.11. XML Type
9.12. JSON Types
9.13. Arrays
9.14. Composite Types
9.15. Range Types
9.16. Domain Types
9.17. Object Identifier Types
9.18. pg_lsn Type
9.19. Pseudo-Types
9.20. Oracle Compatible DataType
9.21. MySQL Compatible DataType
10. Functions and Operators
10.1. Logical Operators
10.2. Comparison Functions and Operators
10.3. Mathematical Functions and Operators
10.4. String Functions and Operators
10.5. Binary String Functions and Operators
10.6. Bit String Functions and Operators
10.7. Pattern Matching
10.8. Data Type Formatting Functions
10.9. Date/Time Functions and Operators
10.10. Enum Support Functions
10.11. Network Address Functions and Operators
10.12. Text Search Functions and Operators
10.13. UUID Functions
10.14. XML Functions
10.15. JSON Functions and Operators
10.16. Sequence Manipulation Functions
10.17. Conditional Expressions
10.18. Array Functions and Operators
10.19. Range Functions and Operators
10.20. Aggregate Functions
10.21. Window Functions
10.22. Subquery Expressions
10.23. Row and Array Comparisons
10.24. Set Returning Functions
10.25. System Information Functions and Operators
10.26. System Administration Functions
10.27. Trigger Functions
10.28. Event Trigger Functions
10.29. Statistics Information Functions
10.30. Oracle Compatible Functions
10.31. MySQL Compatible Functions
11. Type Conversion
11.1. Overview
11.2. Operators
11.3. Functions
11.4. Value Storage
11.5. UNION, CASE, and Related Constructs
11.6. SELECT Output Columns
11.7. Type Compatibility
12. Indexes
12.1. Introduction
12.2. Index Types
12.3. Multicolumn Indexes
12.4. Indexes and ORDER BY
12.5. Combining Multiple Indexes
12.6. Unique Indexes
12.7. Indexes on Expressions
12.8. Partial Indexes
12.9. Index-Only Scans and Covering Indexes
12.10. Operator Classes and Operator Families
12.11. Indexes and Collations
12.12. Examining Index Usage
13. Full Text Search
13.1. Introduction
13.2. Tables and Indexes
13.3. Controlling Text Search
13.4. Additional Features
13.5. Parsers
13.6. Dictionaries
13.7. Configuration Example
13.8. Testing and Debugging Text Search
13.9. Preferred Index Types for Text Search
13.10. ltsql Support
13.11. Limitations
14. Concurrency Control
14.1. Introduction
14.2. Transaction Isolation
14.3. Explicit Locking
14.4. Data Consistency Checks at the Application Level
14.5. Caveats
14.6. Locking and Indexes
15. Performance Tips
15.1. Using EXPLAIN
15.2. Statistics Used by the Planner
15.3. Controlling the Planner with Explicit JOIN Clauses
15.4. Populating a Database
15.5. Non-Durable Settings
15.6. Enable SubQuery Result Cache
15.7. Adaptive work_mem
15.8. Linear Parallel workers
15.9. Plan Hint
16. Parallel Query
16.1. How Parallel Query Works
16.2. When Can Parallel Query Be Used?
16.3. Parallel Plans
16.4. Parallel Safety