HyperSQL User Guide
HyperSQL Database Engine 2.4.1
Edited by , Blaine Simpson, and Fred Toussi
HyperSQL User Guide: HyperSQL Database Engine 2.4.1
by , Blaine Simpson, and Fred Toussi
$Revision: 5805 $
Publication date 2018-05-20 12:12:26-0400
Copyright 2002-2018 Blaine Simpson, Fred Toussi and The HSQL Development Group. Permission is granted to distribute this document without
any alteration under the terms of the HSQLDB license. You are not allowed to distribute or display this document on the web in an altered form.
iii
Table of Contents
Preface ........................................................................................................................................ xiii
Available formats for this document ......................................................................................... xiii
1. Running and Using HyperSQL ....................................................................................................... 1
Introduction ............................................................................................................................. 1
The HSQLDB Jar .................................................................................................................... 1
Running Database Access Tools ................................................................................................. 2
A HyperSQL Database .............................................................................................................. 2
In-Process Access to Database Catalogs ....................................................................................... 3
Server Modes .......................................................................................................................... 4
HyperSQL HSQL Server ................................................................................................... 4
HyperSQL HTTP Server ................................................................................................... 5
HyperSQL HTTP Servlet ................................................................................................... 5
Connecting to a Database Server ......................................................................................... 5
Security Considerations ..................................................................................................... 6
Using Multiple Databases .................................................................................................. 6
Accessing the Data ................................................................................................................... 6
Closing the Database ................................................................................................................ 7
Creating a New Database .......................................................................................................... 7
2. SQL Language ............................................................................................................................. 9
Standards Support .................................................................................................................... 9
SQL Data and Tables ............................................................................................................... 9
Temporary Tables ........................................................................................................... 10
Persistent Tables ............................................................................................................ 10
Short Guide to Data Types ....................................................................................................... 11
Data Types and Operations ...................................................................................................... 12
Numeric Types .............................................................................................................. 12
Boolean Type ................................................................................................................ 14
Character String Types .................................................................................................... 14
Binary String Types ........................................................................................................ 15
Bit String Types ............................................................................................................. 16
Lob Data ...................................................................................................................... 17
Storage and Handling of Java Objects ................................................................................ 17
Type Length, Precision and Scale ...................................................................................... 18
Datetime types ....................................................................................................................... 19
Interval Types ........................................................................................................................ 23
Arrays .................................................................................................................................. 26
Array Definition ............................................................................................................. 26
Array Reference ............................................................................................................. 27
Array Operations ............................................................................................................ 28
Indexes and Query Speed ......................................................................................................... 30
Query Processing and Optimisation ........................................................................................... 31
Indexes and Conditions ................................................................................................... 31
Indexes and Operations ................................................................................................... 31
Indexes and ORDER BY, OFFSET and LIMIT .................................................................... 32
3. Sessions and Transactions ............................................................................................................ 33
Overview .............................................................................................................................. 33
Session Attributes and Variables ............................................................................................... 33
Session Attributes ........................................................................................................... 34
Session Variables ........................................................................................................... 34
Session Tables ............................................................................................................... 34
Transactions and Concurrency Control ....................................................................................... 35
HyperSQL User Guide
iv
Two Phase Locking ........................................................................................................ 35
Two Phase Locking with Snapshot Isolation ........................................................................ 36
Lock Contention in 2PL .................................................................................................. 36
Locks in SQL Routines and Triggers ................................................................................. 36
MVCC ......................................................................................................................... 36
Choosing the Transaction Model ....................................................................................... 37
Schema and Database Change ........................................................................................... 38
Simultaneous Access to Tables ......................................................................................... 38
Viewing Sessions ........................................................................................................... 38
Session and Transaction Control Statements ................................................................................ 39
4. Schemas and Database Objects ...................................................................................................... 46
Overview .............................................................................................................................. 46
Schemas and Schema Objects ................................................................................................... 46
Names and References .................................................................................................... 47
Character Sets ................................................................................................................ 47
Collations ...................................................................................................................... 48
Distinct Types ................................................................................................................ 49
Domains ....................................................................................................................... 49
Number Sequences ......................................................................................................... 49
Tables .......................................................................................................................... 51
Views ........................................................................................................................... 52
Constraints .................................................................................................................... 52
Assertions ..................................................................................................................... 53
Triggers ........................................................................................................................ 53
Routines ....................................................................................................................... 54
Indexes ......................................................................................................................... 54
Synonyms ..................................................................................................................... 54
Statements for Schema Definition and Manipulation ..................................................................... 54
Common Elements and Statements .................................................................................... 54
Renaming Objects .......................................................................................................... 56
Commenting Objects ....................................................................................................... 56
Schema Creation ............................................................................................................ 57
Table Creation ............................................................................................................... 58
Table Manipulation ......................................................................................................... 63
View Creation and Manipulation ....................................................................................... 68
Domain Creation and Manipulation .................................................................................... 69
Trigger Creation ............................................................................................................. 70
Routine Creation ............................................................................................................ 72
Sequence Creation .......................................................................................................... 74
SQL Procedure Statement ................................................................................................ 76
Other Schema Object Creation .......................................................................................... 76
The Information Schema .......................................................................................................... 80
Predefined Character Sets, Collations and Domains ............................................................... 80
Views in INFORMATION SCHEMA ................................................................................ 80
Visibility of Information .................................................................................................. 80
Name Information .......................................................................................................... 80
Data Type Information .................................................................................................... 81
Product Information ........................................................................................................ 81
Operations Information .................................................................................................... 81
SQL Standard Views ....................................................................................................... 81
5. Text Tables ................................................................................................................................ 88
Overview .............................................................................................................................. 88
The Implementation ................................................................................................................ 88
Definition of Tables ........................................................................................................ 88
HyperSQL User Guide
v
Scope and Reassignment .................................................................................................. 88
Null Values in Columns of Text Tables .............................................................................. 89
Configuration ................................................................................................................. 89
Disconnecting Text Tables ............................................................................................... 91
Text File Usage ..................................................................................................................... 91
Text File Global Properties ...................................................................................................... 92
Transactions .......................................................................................................................... 93
6. Access Control ........................................................................................................................... 94
Overview .............................................................................................................................. 94
Authorizations and Access Control ............................................................................................ 94
Built-In Roles and Users .................................................................................................. 95
Listing Users and Roles ................................................................................................... 96
Access Rights ................................................................................................................ 96
Statements for Authorization and Access Control ......................................................................... 97
7. Data Access and Change ............................................................................................................ 102
Overview ............................................................................................................................. 102
Cursors And Result Sets ........................................................................................................ 102
Columns and Rows ....................................................................................................... 102
Navigation ................................................................................................................... 102
Updatability ................................................................................................................. 103
Sensitivity ................................................................................................................... 104
Holdability ................................................................................................................... 104
Autocommit ................................................................................................................. 104
JDBC Overview ........................................................................................................... 104
JDBC Parameters .......................................................................................................... 105
JDBC and Data Change Statements .................................................................................. 105
JDBC Callable Statement ............................................................................................... 106
JDBC Returned Values .................................................................................................. 106
Cursor Declaration ........................................................................................................ 107
Syntax Elements ................................................................................................................... 107
Literals ....................................................................................................................... 107
References, etc. ............................................................................................................ 111
Value Expression .......................................................................................................... 112
Predicates .................................................................................................................... 119
Aggregate Functions ...................................................................................................... 125
Other Syntax Elements .................................................................................................. 127
Data Access Statements ......................................................................................................... 128
Select Statement ........................................................................................................... 129
Table .......................................................................................................................... 129
Subquery ..................................................................................................................... 129
Query Specification ....................................................................................................... 130
Table Expression .......................................................................................................... 130
Joined Table ................................................................................................................ 133
Selection ..................................................................................................................... 135
Projection .................................................................................................................... 135
Computed Columns ....................................................................................................... 136
Naming ....................................................................................................................... 136
Grouping Operations ..................................................................................................... 137
Aggregation ................................................................................................................. 138
Set Operations .............................................................................................................. 138
With Clause and Recursive Queries .................................................................................. 138
Query Expression .......................................................................................................... 139
Ordering ...................................................................................................................... 140
Slicing ........................................................................................................................ 141