2414
2439
control and error handling).
2416
2441
Some of the examples below use quoting which works exactly
2417
as-is for any normal UNIX shell.
2442
as-is for any Bourne-compatible UNIX shell.
2443
(Only line-continuation would need to be changed for C-compatible
2418
2445
I have not yet tested these commands on Windows, and I doubt
2419
2446
whether the quoting will work just like this (though it is
2421
2448
SqlTool is still a very useful tool even if you have no quoting
2422
2449
capability at all.
2424
This document is now updated for version 1.46 of SqlTool and
2425
1.114 of SqlFile (the latter is the class which does most of the
2451
If you are using SqlTool from a HSQDLB distribution before
2452
version 1.8.0.0 final, you should use the documentation with that
2454
(because, for brevity, I do not here indicate changes made to
2455
behavior before 1.8.0.0 final).
2456
This document is now updated for the current versions of SqlTool
2457
and SqlFile at the time I am writing this (versions 1.50 and
2458
1.130 correspondingly, SqlFile is the class which does most of the
2426
2459
work for SqlTool).
2460
Therefore, if you are using a version of SqlTool or SqlFile that
2461
is more than a couple revisions greater, you should find a newer
2462
version of this document.
2463
(The imprecision is due to content-independent revision increments
2464
at build time, and the likelihood of one or two
2465
behavior-independent bug fixes after public releases).
2427
2466
The startup banner will report both versions when you run SqlTool
2429
I expect this version of this document to accurately describe
2430
SqlTool for some unknown number of versions into the future.
2431
</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11217"></a>Recent changes</h3></div></div><div></div></div><p>This section lists changes to SqlTool since the last
2468
</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11222"></a>Recent changes</h3></div></div><div></div></div><p>This section lists changes to SqlTool since the last
2432
2469
major release of HSQLDB.
2433
For this version of this document, that means, changes since
2434
HSQLDB versions 1.7.x.
2470
For this revision of this document, this list consists of
2471
significant changes made to SqlTool AFTER the final 1.8.0.0
2435
2473
</p><div class="itemizedlist"><ul type="disc"><li>
2436
Slight adjustments to command-line switch behavior to make
2437
them more convenient for the most common forms of usage.
2439
Changed PL alias prefix from * to / (in order to allow for
2440
the following improvement).
2442
Removed the funny whitespace requirements for PL commands.
2444
Uppercase/lowercase requirements for special commands are
2445
relegated to the database.
2446
Therefore, in special commands only, you are safest to key
2447
in object names in the case exactly as the real object name
2449
This is the only way for me to remove ambiguity from
2450
case-specific object names without having to code different
2451
rules for every database.
2452
(Because, for example, Postgresql defaults object names to
2453
lowercase and Oracle defaults them to uppercase).
2455
Added special command \dn.
2457
Added special command \ds (old \ds command is now \dS).
2459
Added special command \di.
2461
Renamed special command \* to \c. (\* still supported
2462
for backward compatibility).
2464
Not so stingy about saving commands in history.
2466
Allow optional filter substring for many more \d commands,
2467
including for "\d TABLENAME".
2469
Implemented special use of substrings ending with dot.
2470
These do not just filter on the string, but mean to
2471
filter to only objects with this exact schema.
2473
\da and \ds commands now work for HSQLDB servers, even
2474
though HSQLDB Aliases and Sequences are not listed in the
2477
Improved exception handling.
2479
Implemented Raw SQL mode, and ability for users to enter
2482
Fixed open Statement bug (HSQLDB bug #1191524).
2484
Improved Oracle idiosyncracy work-arounds.
2486
Added support for all non-text type fields, including BLOBs.
2488
Can download and upload both ASCII and binary column
2489
values to/from local files.
2491
Better display of null values occurring in result sets.
2493
RC file functionality isolated into separate class, RCData.
2494
Other programs can now use RC files by using this class.
2495
</li></ul></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="baremin-section"></a>The Bare Minimum You Need to Know to Run SqlTool</h2></div></div><div></div></div><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>
2474
Fixed bug where PL "end" command was still requiring old
2475
syntax (wrt white space).
2476
Fixed for HSQLDB v. 1.8.0.2.
2478
Fixed NPE sometimes encountered when fetching null
2480
Fixed for HSQLDB v. 1.8.0.2.
2482
Implemented new \dr command for HSQLDB and Sybase servers.
2483
Implemented \du for Sybase.
2484
Added for HSQLDB v. 1.8.0.3.
2486
Implemented CSV eXport and iMport commands \x and \m.
2487
Added for HSQLDB v. 1.8.0.3.
2489
Implemented method for specifying RC file parameters as a
2490
command-line switch. Modified SqlTool to now accepts case
2491
insensitive command-line switches. Added for HSQLDB v. 1.8.1.
2493
When recently changed or added features (i.e, those items
2494
in the preceding list) are described in the main document
2495
below, there is a <span class="emphasis"><em>Note</em></span> at that point
2496
indicating when the feature was added or changed.
2497
</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="baremin-section"></a>The Bare Minimum You Need to Know to Run SqlTool</h2></div></div><div></div></div><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>
2496
2498
If you are using an Oracle database server, it will commit your
2497
2499
current transaction if you cleanly disconnect, regardless of
2498
2500
whether you have set auto-commit or not.
4503
4523
at the end of the
4504
4524
<a href="#baremin-section" title="The Bare Minimum You Need to Know to Run SqlTool">The Bare Minimum</a> section,
4505
4525
but use your new file in place of <tt class="filename">hsqldb.jar</tt>.
4506
</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N11AFB"></a>Unit Testing SqlTool</h2></div></div><div></div></div><p>
4507
A unit testing framework is in place.
4508
This assures the robustness of SqlTool.
4509
See the file <tt class="filename">testrun/sqltool/readme.txt</tt>
4510
for instructions on running, modifying, or creating unit
4512
To create a new unit test, you create a SQL file and embed
4513
metacommands in the SQL file inside of comments.
4514
The metacommands tell the test harness
4515
(<tt class="classname">org.hsqldb.test.SqlToolHarness</tt>)
4516
how to run SqlTool (like with what arguments) and what
4517
output to expect (i.e. the test criteria).
4518
You can run tests without JUnit, or you can make a JUnit
4519
wrapper in the normal fashion. Any SQL test file can
4520
be added to our JUnit SqlTool test suite by just adding
4521
the SQL file name and description to the
4522
<tt class="filename">testrun/sqltool/*.list</tt> file for the
4523
desired JUnit test method.
4525
(The SqlTool unit tests require java 1.4).
4526
</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sqlsyntax-chapter"></a>Chapter 9. SQL Syntax</h2></div><div><div class="authorgroup"><h3 class="corpauthor">The Hypersonic SQL Group</h3><div class="author"><h3 class="author"><span class="firstname">Fred</span> <span class="surname">Toussi</span></h3><div class="affiliation"><span class="orgname">HSQLDB Development Group<br></span></div><tt class="email"><<a href="mailto:ft@cluedup.com">ft@cluedup.com</a>></tt></div><div class="author"><h3 class="author"><span class="firstname">Peter</span> <span class="surname">Hudson</span></h3><div class="affiliation"><span class="orgname">HSQLDB Development Group<br></span></div></div><div class="author"><h3 class="author"><span class="firstname">Joe</span> <span class="surname">Maher</span></h3><div class="affiliation"><span class="orgname">HSQLDB Development Group<br></span></div><tt class="email"><<a href="mailto:jrmaher@ameritech.net">jrmaher@ameritech.net</a>></tt></div><h4 class="editedby">Edited by</h4><h3 class="editor"><span class="firstname">Blaine</span> <span class="surname">Simpson</span></h3></div></div><div><p class="pubdate">$Date: 2005/06/30 22:39:11 $</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#N11B4F">Notational Conventions Used in this Chapter</a></span></dt><dt><span class="section"><a href="#N11B6C">SQL Commands</a></span></dt><dd><dl><dt><span class="section"><a href="#alter_index-section">ALTER INDEX</a></span></dt><dt><span class="section"><a href="#alter_sequence-section">ALTER SEQUENCE</a></span></dt><dt><span class="section"><a href="#N11B8B">ALTER SCHEMA</a></span></dt><dt><span class="section"><a href="#alter_table-section">ALTER TABLE</a></span></dt><dt><span class="section"><a href="#alter_user-section">ALTER USER</a></span></dt><dt><span class="section"><a href="#call-section">CALL</a></span></dt><dt><span class="section"><a href="#checkpoint-section">CHECKPOINT</a></span></dt><dt><span class="section"><a href="#commit-section">COMMIT</a></span></dt><dt><span class="section"><a href="#connect-section">CONNECT</a></span></dt><dt><span class="section"><a href="#create_alias-section">CREATE ALIAS</a></span></dt><dt><span class="section"><a href="#create_index-section">CREATE INDEX</a></span></dt><dt><span class="section"><a href="#create_role-section">CREATE ROLE</a></span></dt><dt><span class="section"><a href="#N11CA5">CREATE SCHEMA</a></span></dt><dt><span class="section"><a href="#create_sequence-section">CREATE SEQUENCE</a></span></dt><dt><span class="section"><a href="#create_table-section">CREATE TABLE</a></span></dt><dt><span class="section"><a href="#create_trigger-section">CREATE TRIGGER</a></span></dt><dt><span class="section"><a href="#create_user-section">CREATE USER</a></span></dt><dt><span class="section"><a href="#create_view-section">CREATE VIEW</a></span></dt><dt><span class="section"><a href="#delete-section">DELETE</a></span></dt><dt><span class="section"><a href="#disconnect-section">DISCONNECT</a></span></dt><dt><span class="section"><a href="#drop_index-section">DROP INDEX</a></span></dt><dt><span class="section"><a href="#N11E14">DROP ROLE</a></span></dt><dt><span class="section"><a href="#drop_sequence-section">DROP SEQUENCE</a></span></dt><dt><span class="section"><a href="#N11E2E">DROP SCHEMA</a></span></dt><dt><span class="section"><a href="#drop_table-section">DROP TABLE</a></span></dt><dt><span class="section"><a href="#drop_trigger-section">DROP TRIGGER</a></span></dt><dt><span class="section"><a href="#drop_user-section">DROP USER</a></span></dt><dt><span class="section"><a href="#drop_view-section">DROP VIEW</a></span></dt><dt><span class="section"><a href="#explain-section">EXPLAIN PLAN</a></span></dt><dt><span class="section"><a href="#grant-section">GRANT</a></span></dt><dt><span class="section"><a href="#insert-section">INSERT</a></span></dt><dt><span class="section"><a href="#revoke-section">REVOKE</a></span></dt><dt><span class="section"><a href="#rollback-section">ROLLBACK</a></span></dt><dt><span class="section"><a href="#savepoint-section">SAVEPOINT</a></span></dt><dt><span class="section"><a href="#script-section">SCRIPT</a></span></dt><dt><span class="section"><a href="#select-section">SELECT</a></span></dt><dt><span class="section"><a href="#set_autocommit-section">SET AUTOCOMMIT</a></span></dt><dt><span class="section"><a href="#collation-section">SET DATABASE COLLATION</a></span></dt><dt><span class="section"><a href="#N11FBD">SET CHECKPOINT DEFRAG</a></span></dt><dt><span class="section"><a href="#set_ignorecase-section">SET IGNORECASE</a></span></dt><dt><span class="section"><a href="#set_logsize-section">SET LOGSIZE</a></span></dt><dt><span class="section"><a href="#set_password-section">SET PASSWORD</a></span></dt><dt><span class="section"><a href="#set_property-section">SET PROPERTY</a></span></dt><dt><span class="section"><a href="#set_refint-section">SET REFERENTIAL INTEGRITY</a></span></dt><dt><span class="section"><a href="#N1201E">SET SCHEMA</a></span></dt><dt><span class="section"><a href="#set_scriptformat-section">SET SCRIPTFORMAT</a></span></dt><dt><span class="section"><a href="#set_table_index-section">SET TABLE INDEX</a></span></dt><dt><span class="section"><a href="#set_table_readonly-section">SET TABLE READONLY</a></span></dt><dt><span class="section"><a href="#set_table_source-section">SET TABLE SOURCE</a></span></dt><dt><span class="section"><a href="#set_write_delay-section">SET WRITE DELAY</a></span></dt><dt><span class="section"><a href="#shutdown-section">SHUTDOWN</a></span></dt><dt><span class="section"><a href="#update-section">UPDATE</a></span></dt></dl></dd><dt><span class="section"><a href="#datatypes-section">Data Types</a></span></dt><dt><span class="section"><a href="#N12234">SQL Comments</a></span></dt><dt><span class="section"><a href="#stored-section">Stored Procedures / Functions</a></span></dt><dt><span class="section"><a href="#N12265">Built-in Functions and Stored Procedures</a></span></dt><dt><span class="section"><a href="#expression-section">SQL Expression</a></span></dt></dl></div><p>HSQLDB version 1.8.0 supports the SQL statements and syntax described
4527
in this chapter.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N11B4F"></a>Notational Conventions Used in this Chapter</h2></div></div><div></div></div><p><tt class="literal">[A]</tt> means A is optional.</p><p><tt class="literal">{ B | C }</tt> means either B or C must be
4526
</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N11B18"></a>Character-Separated-Value Imports and Exports</h2></div></div><div></div></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
4527
These features were added for version 1.8.0.3 of HSQLDB.
4528
</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
4529
This feature is independent of HSQLDB
4530
<a href="#texttables-chapter" title="Chapter 6. Text Tables">Text Tables</a>,
4531
a server-side feature of HSQLDB.
4532
It makes no difference to SqlTool whether the source or target
4533
table of your export/import is a memory, cache, or text table.
4534
Indeed, like all features of SqlTool, it works fine with other
4536
It works great, for example to migrate data from a table
4537
of one type to a table of another type, or to another schema,
4538
or to another database instance, or to another database system.
4540
Because of common usage of the term, I call this feature
4541
<span class="emphasis"><em>CSV</em></span> imports and exports, even though the
4542
delimiters are not constrained to single characters, but
4544
Use the <tt class="literal">\x</tt> command to eXport a table to a
4545
CSV file, and the <tt class="literal">\m</tt> command to iMport a
4546
CSV file into a pre-existing table.
4548
Just as the delimiter capability is more general than traditional
4549
CSV delimiters, the export function is also more general than
4550
just a table data exporter.
4551
Besides the trivial generalization that you may specify a
4552
view or other virtual table name in place of a table name,
4553
you can alternatively export the output of any query which
4554
produces normal text output.
4555
A benefit to this approach is that it allows you to export only
4556
some columns of a table, and to specify a WHERE clause to narrow
4557
down the rows to be exported (or perform any other SQL
4558
transformation, mapping, join, etc.).
4559
One specific use for this would be to exclude columns of
4560
binary data (which can be exported by other means, such as
4561
a PL loop to store binary values to files with the \bd command).
4563
Note that the import command will not create a new table.
4564
This is because of the impossibility of guessing appropriate
4565
types and constraints based only on column names and a data
4566
sampling (which is all that a CSV-importer has access to).
4567
Therefore, if you wish to populate a new table, create the
4568
table before running the import.
4569
The import file does not need to have data for all columns of a
4571
The only required columns are those required by non-null and
4573
One specific reason to omit columns is if you want values of
4574
some columns to be created automatically by column DEFAULT
4575
settings, triggers, HSQLDB identity sequences, etc.
4576
Another reason would be to skip binary columns.
4577
</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11B36"></a>Simple CSV exports and imports using default settings</h3></div></div><div></div></div><p>
4578
Even if you need to change delimiters, table names, or file
4579
names from the defaults, I suggest that you run one export
4580
and import with default settings as a practice run.
4581
A memory-only HSQLDB instance is ideal for test runs like this.
4583
This command exports the table <tt class="literal">icf.projects</tt>
4584
to the file <tt class="filename">projects.csv</tt> in the current
4585
directory (where you invoked SqlTool from).
4586
By default, the output file name will be the specified source
4587
table name plus the extension <tt class="literal">.csv</tt>.
4588
<div class="example"><a name="N11B49"></a><p class="title"><b>Example 8.14. CSV Export Example</b></p><pre class="screen"> SET SCHEMA icf;
4591
We could also have run <tt class="literal">\x icf.projects</tt>
4592
(which would have created a file named
4593
<tt class="filename">icf.projects.csv</tt>)
4594
instead of changing the session schema.
4595
In this example we have chosen to make the export file name
4596
independent of the schema to facilitate importing it into
4599
Take a look at the output file.
4600
Notice that the first line consists of column names, not
4602
This line is present because it will be needed if the file is
4603
to used for a CSV import.
4604
Notice the following characterstics about the export data.
4605
The column delimiter is the pipe character "|".
4606
The record delimiter is the default line delimiter character(s)
4607
for your operating system.
4608
The string used to represent database <tt class="literal">NULL</tt>s
4609
is <tt class="literal">[null]</tt>.
4610
See the next section for how to change these from their default
4613
This command imports the data from the file
4614
<tt class="filename">projects.csv</tt> in the current
4615
directory (where you invoked SqlTool from) into the table
4616
<tt class="literal">newschema.projects</tt>.
4617
By default, the output table name will be the input filename
4618
after removing optional leading directory and trailing final
4620
<div class="example"><a name="N11B6C"></a><p class="title"><b>Example 8.15. CSV Import Example</b></p><pre class="screen"> SET SCHEMA newschema;
4623
If the CSV file was named with the target schema, you would
4624
have skipped the <tt class="literal">SET SCHEMA</tt> command, like
4625
<tt class="literal">\m newschema.projects.csv</tt>.
4626
</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11B7B"></a>Specifying queries, delimiters, file names, table names,
4627
columns</h3></div></div><div></div></div><p>
4628
The header line in the CSV file is required at this time.
4629
(If there is user demand, it can be made optional for
4630
exporting, but it will remain required for importing).
4632
Your export will fail if the column or record delimiter, or
4633
the null representation value occurs in the data being
4635
You change these values by setting the PL variables
4636
<tt class="literal">*CSV_COL_DELIM</tt>,
4637
<tt class="literal">*CSV_ROW_DELIM</tt>,
4638
<tt class="literal">*CSV_NULL_REP</tt>.
4639
Notice that the asterisk is part of the variable names, to
4640
indicate that these variables are used by SqlTool internally.
4641
You can use the escape sequences \n, \r, and \t in the
4643
For example, to change the column delimiter to the tab character,
4644
you would give the command
4645
<div class="informalexample"><pre class="screen">
4646
* *CSV_COL_DELIM = \t</pre></div>
4648
For imports, you must always specify the source CSV file path.
4649
If you want to <span class="emphasis"><em>export</em></span> to a different file
4650
than one in the current directory named according to the source
4651
table, set the PL variable <tt class="literal">*CSV_FILEPATH</tt>,
4653
<div class="informalexample"><pre class="screen">
4654
* *CSV_FILEPATH = /tmp/dtbl.csv</pre></div>
4656
For exports, you must always specify the source table name
4658
If you want to <span class="emphasis"><em>import</em></span> to a table other
4659
than that derived from
4660
the input CSV file name, set the PL variable
4661
<tt class="literal">*CSV_TABLENAME</tt>.
4662
The table name may contain a schema name prefix.
4664
At this time, you must import all columns that have data in
4666
If there is demand to specify an optional list of columns to
4667
import, I'll gladly add that feature.
4669
You can specify a query instead of a tablename with the
4670
\x command in order to filter or transform data from a table
4671
or view, or to export the output of a join, etc.
4672
You must set the PL variable <tt class="literal">*CSV_FILEPATH</tt>,
4673
as explained above (since there is no table name from which to
4674
automatically map a file name).
4675
<div class="example"><a name="N11BB2"></a><p class="title"><b>Example 8.16. CSV Export of an Arbitrary SELECT Statement</b></p><pre class="screen"> * *CSV_FILEPATH = outfile.txt
4676
\x SELECT entrydate, 2 * aval "Double aval", modtime from bs.dtbl</pre></div>
4677
Note that I specified the column label alias "Double aval"
4678
so that the label for that column in the CSV file header will
4680
</p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sqlsyntax-chapter"></a>Chapter 9. SQL Syntax</h2></div><div><div class="authorgroup"><h3 class="corpauthor">The Hypersonic SQL Group</h3><div class="author"><h3 class="author"><span class="firstname">Fred</span> <span class="surname">Toussi</span></h3><div class="affiliation"><span class="orgname">HSQLDB Development Group<br></span></div><tt class="email"><<a href="mailto:ft@cluedup.com">ft@cluedup.com</a>></tt></div><div class="author"><h3 class="author"><span class="firstname">Peter</span> <span class="surname">Hudson</span></h3><div class="affiliation"><span class="orgname">HSQLDB Development Group<br></span></div></div><div class="author"><h3 class="author"><span class="firstname">Joe</span> <span class="surname">Maher</span></h3><div class="affiliation"><span class="orgname">HSQLDB Development Group<br></span></div><tt class="email"><<a href="mailto:jrmaher@ameritech.net">jrmaher@ameritech.net</a>></tt></div><h4 class="editedby">Edited by</h4><h3 class="editor"><span class="firstname">Blaine</span> <span class="surname">Simpson</span></h3></div></div><div><p class="pubdate">$Date: 2005/11/06 22:13:26 $</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#N11BFC">Notational Conventions Used in this Chapter</a></span></dt><dt><span class="section"><a href="#N11C19">SQL Commands</a></span></dt><dd><dl><dt><span class="section"><a href="#alter_index-section">ALTER INDEX</a></span></dt><dt><span class="section"><a href="#alter_sequence-section">ALTER SEQUENCE</a></span></dt><dt><span class="section"><a href="#N11C38">ALTER SCHEMA</a></span></dt><dt><span class="section"><a href="#alter_table-section">ALTER TABLE</a></span></dt><dt><span class="section"><a href="#alter_user-section">ALTER USER</a></span></dt><dt><span class="section"><a href="#call-section">CALL</a></span></dt><dt><span class="section"><a href="#checkpoint-section">CHECKPOINT</a></span></dt><dt><span class="section"><a href="#commit-section">COMMIT</a></span></dt><dt><span class="section"><a href="#connect-section">CONNECT</a></span></dt><dt><span class="section"><a href="#create_alias-section">CREATE ALIAS</a></span></dt><dt><span class="section"><a href="#create_index-section">CREATE INDEX</a></span></dt><dt><span class="section"><a href="#create_role-section">CREATE ROLE</a></span></dt><dt><span class="section"><a href="#N11D63">CREATE SCHEMA</a></span></dt><dt><span class="section"><a href="#create_sequence-section">CREATE SEQUENCE</a></span></dt><dt><span class="section"><a href="#create_table-section">CREATE TABLE</a></span></dt><dt><span class="section"><a href="#create_trigger-section">CREATE TRIGGER</a></span></dt><dt><span class="section"><a href="#create_user-section">CREATE USER</a></span></dt><dt><span class="section"><a href="#create_view-section">CREATE VIEW</a></span></dt><dt><span class="section"><a href="#delete-section">DELETE</a></span></dt><dt><span class="section"><a href="#disconnect-section">DISCONNECT</a></span></dt><dt><span class="section"><a href="#drop_index-section">DROP INDEX</a></span></dt><dt><span class="section"><a href="#N11ED7">DROP ROLE</a></span></dt><dt><span class="section"><a href="#drop_sequence-section">DROP SEQUENCE</a></span></dt><dt><span class="section"><a href="#N11EF1">DROP SCHEMA</a></span></dt><dt><span class="section"><a href="#drop_table-section">DROP TABLE</a></span></dt><dt><span class="section"><a href="#drop_trigger-section">DROP TRIGGER</a></span></dt><dt><span class="section"><a href="#drop_user-section">DROP USER</a></span></dt><dt><span class="section"><a href="#drop_view-section">DROP VIEW</a></span></dt><dt><span class="section"><a href="#explain-section">EXPLAIN PLAN</a></span></dt><dt><span class="section"><a href="#grant-section">GRANT</a></span></dt><dt><span class="section"><a href="#insert-section">INSERT</a></span></dt><dt><span class="section"><a href="#revoke-section">REVOKE</a></span></dt><dt><span class="section"><a href="#rollback-section">ROLLBACK</a></span></dt><dt><span class="section"><a href="#savepoint-section">SAVEPOINT</a></span></dt><dt><span class="section"><a href="#script-section">SCRIPT</a></span></dt><dt><span class="section"><a href="#select-section">SELECT</a></span></dt><dt><span class="section"><a href="#set_autocommit-section">SET AUTOCOMMIT</a></span></dt><dt><span class="section"><a href="#collation-section">SET DATABASE COLLATION</a></span></dt><dt><span class="section"><a href="#N1208B">SET CHECKPOINT DEFRAG</a></span></dt><dt><span class="section"><a href="#set_ignorecase-section">SET IGNORECASE</a></span></dt><dt><span class="section"><a href="#set_initialschema-section">SET INITIAL SCHEMA </a></span></dt><dt><span class="section"><a href="#set_logsize-section">SET LOGSIZE</a></span></dt><dt><span class="section"><a href="#set_password-section">SET PASSWORD</a></span></dt><dt><span class="section"><a href="#set_property-section">SET PROPERTY</a></span></dt><dt><span class="section"><a href="#set_refint-section">SET REFERENTIAL INTEGRITY</a></span></dt><dt><span class="section"><a href="#set_schema-section">SET SCHEMA</a></span></dt><dt><span class="section"><a href="#set_scriptformat-section">SET SCRIPTFORMAT</a></span></dt><dt><span class="section"><a href="#set_table_index-section">SET TABLE INDEX</a></span></dt><dt><span class="section"><a href="#set_table_readonly-section">SET TABLE READONLY</a></span></dt><dt><span class="section"><a href="#set_table_source-section">SET TABLE SOURCE</a></span></dt><dt><span class="section"><a href="#set_write_delay-section">SET WRITE DELAY</a></span></dt><dt><span class="section"><a href="#shutdown-section">SHUTDOWN</a></span></dt><dt><span class="section"><a href="#update-section">UPDATE</a></span></dt></dl></dd><dt><span class="section"><a href="#schemanaming-section">Schema object naming</a></span></dt><dt><span class="section"><a href="#datatypes-section">Data Types</a></span></dt><dt><span class="section"><a href="#N12364">SQL Comments</a></span></dt><dt><span class="section"><a href="#stored-section">Stored Procedures / Functions</a></span></dt><dt><span class="section"><a href="#N12395">Built-in Functions and Stored Procedures</a></span></dt><dt><span class="section"><a href="#expression-section">SQL Expression</a></span></dt></dl></div><p>HSQLDB version 1.8.0 supports the SQL statements and syntax described
4681
in this chapter.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N11BFC"></a>Notational Conventions Used in this Chapter</h2></div></div><div></div></div><p><tt class="literal">[A]</tt> means A is optional.</p><p><tt class="literal">{ B | C }</tt> means either B or C must be
4528
4682
used.</p><p><tt class="literal">[{ B | C }]</tt> means either B or C may optionally be
4529
4683
used, or nothing at all.</p><p><tt class="literal">(</tt> and <tt class="literal">)</tt> are the actual
4530
characters '(' and ')' used in statements.</p><p>UPPERCASE words are keywords</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N11B6C"></a>SQL Commands</h2></div></div><div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="alter_index-section"></a>ALTER INDEX<sup>[<a href="#ftn.posthyper" name="posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER INDEX <indexname> RENAME TO <newname>;</pre><p>Index names can be changed so long as they do not conflict with
4531
other user-defined or sytem-defined names.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="alter_sequence-section"></a>ALTER SEQUENCE<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER SEQUENCE <sequencename> RESTART WITH <value>;</pre><p>Resets the next value to be returned from the sequence.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11B8B"></a>ALTER SCHEMA<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER SCHEMA <schemaname> RENAME TO <newname>;</pre><p>Renames schema as specified. All objects of the schema will
4532
hereafter be accessible only with the new schema name.</p><p>Requires Administrative privileges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="alter_table-section"></a>ALTER TABLE<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER TABLE <tablename> ADD [COLUMN] <columnname> <a href="#datatypes-section" title="Data Types">Datatype</a> [(columnSize[,precision])]
4533
[{DEFAULT <defaultValue> |
4684
characters '(' and ')' used in statements.</p><p>UPPERCASE words are keywords</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N11C19"></a>SQL Commands</h2></div></div><div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="alter_index-section"></a>ALTER INDEX<sup>[<a href="#ftn.posthyper" name="posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER INDEX <indexname> RENAME TO <newname>;</pre><p>Index names can be changed so long as they do not conflict with
4685
other user-defined or sytem-defined names.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="alter_sequence-section"></a>ALTER SEQUENCE<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER SEQUENCE <sequencename> RESTART WITH <value>;</pre><p>Resets the next value to be returned from the sequence.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11C38"></a>ALTER SCHEMA<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER SCHEMA <schemaname> RENAME TO <newname>;</pre><p>Renames the schema as specified. All objects of the schema will
4686
hereafter be accessible only with the new schema name.</p><p>Requires Administrative privileges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="alter_table-section"></a>ALTER TABLE<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER TABLE <tablename> ADD [COLUMN] <columnname> <a href="#datatypes-section" title="Data Types">Datatype</a>
4687
[(columnSize[,precision])] [{DEFAULT <defaultValue> |
4534
4688
GENERATED BY DEFAULT AS IDENTITY (START WITH <n>[, INCREMENT BY <m>])}] |
4535
4689
[[NOT] NULL] [IDENTITY] [PRIMARY KEY]
4536
4690
[BEFORE <existingcolumn>];</pre><p>Adds the column to the end of the column list. The optional BEFORE
4555
4709
(similar to previous item).</li><li>Depending on the type of change, the table may have to be
4556
4710
empty for the command to work. It always works when the type of change
4557
4711
is possible in general and the individual existing values can all be
4558
converted.</li></ul></div><pre class="programlisting">ALTER TABLE <tablename> ALTER COLUMN <columnname> RESTART WITH <new sequence vale></pre><p>This form is used exclusively for IDENTITY columns and changes the
4559
next automatic value for the identity sequence.</p><pre class="programlisting">ALTER TABLE <tablename> ADD [CONSTRAINT <constraintname>] CHECK (<search condition>);</pre><p>Adds a check constraint to the table. In the current version, a
4712
converted.</li></ul></div><pre class="programlisting">ALTER TABLE <tablename> ALTER COLUMN <columnname>
4713
RESTART WITH <new sequence value></pre><p>This form is used exclusively for IDENTITY columns and changes the
4714
next automatic value for the identity sequence.</p><pre class="programlisting">ALTER TABLE <tablename> ADD [CONSTRAINT <constraintname>]
4715
CHECK (<search condition>);</pre><p>Adds a check constraint to the table. In the current version, a
4560
4716
check constraint can reference only the row being inserted or
4561
4717
updated.</p><pre class="programlisting">ALTER TABLE <tablename> ADD [CONSTRAINT <constraintname>] UNIQUE (<column list>);</pre><p>Adds a unique constraint to the table. This will not work if there
4562
4718
is already a unique constraint covering exactly the same <column
4563
4719
list>.</p><p>This will work only if the values of the column list for the
4564
existing rows are unique or include a null value.</p><pre class="programlisting">ALTER TABLE <tablename> ADD [CONSTRAINT <constraintname>] PRIMARY KEY (<column list>);</pre><p>Adds a primary key constraint to the table, using the same
4720
existing rows are unique or include a null value.</p><pre class="programlisting">ALTER TABLE <tablename> ADD [CONSTRAINT <constraintname>]
4721
PRIMARY KEY (<column list>);</pre><p>Adds a primary key constraint to the table, using the same
4565
4722
constraint syntax as when the primary key is specified in a table
4566
definition.</p><pre class="programlisting">ALTER TABLE <tablename> ADD [CONSTRAINT <constraintname>] FOREIGN KEY (<column list>) REFERENCES <exptablename> (<column list>)
4723
definition.</p><pre class="programlisting">ALTER TABLE <tablename>
4724
ADD [CONSTRAINT <constraintname>] FOREIGN KEY (<column list>)
4725
REFERENCES <exptablename> (<column list>)
4567
4726
[ON {DELETE | UPDATE} {CASCADE | SET DEFAULT | SET NULL}];</pre><p>Adds a foreign key constraint to the table, using the same
4568
4727
constraint syntax as when the foreign key is specified in a table
4569
4728
definition.</p><p>This will fail if for each existing row in the referring table, a
4570
4729
matching row (with equal values for the column list) is not found in the
4571
4730
referenced tables.</p><pre class="programlisting">ALTER TABLE <tablename> DROP CONSTRAINT <constraintname>;</pre><p>Drop a named unique, check or foreign key constraint from the
4572
4731
table.</p><pre class="programlisting">ALTER TABLE <tablename> RENAME TO <newname>;</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="alter_user-section"></a>ALTER USER<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">ALTER USER <username> SET PASSWORD <password>;</pre><p>Changes the password for an existing user. Password must be double
4573
quoted. Use "" for an empty password.</p><p>Only an administrator can do this.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="call-section"></a>CALL</h3></div></div><div></div></div><pre class="programlisting">CALL <a href="#expression-section" title="SQL Expression">Expression</a>;</pre><p>Any expression can be called like a stored procedure, including,
4732
quoted. Use "" for an empty password.</p><p>DBA's may change users' base default schema name with the comand
4733
<pre class="programlisting">ALTER USER <username> SET INITIAL SCHEMA <schemaname>;</pre>
4734
This is the schema which database object names will resolve to for this
4735
user, unless overridden as explained in <a href="#schemanaming-section" title="Schema object naming">Schema object naming</a>. For
4736
reasons of backwards compatibility, the initial schema value will not be
4737
persisted across database shutdowns until HSQLDB version 1.8.1. (I.e.,
4738
INITIAL SCHEMA settings will be lost upon database shutdown with HSQLDB
4739
versions lower than version 1.8.1).</p><p>Only an administrator may use these commands.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="call-section"></a>CALL</h3></div></div><div></div></div><pre class="programlisting">CALL <a href="#expression-section" title="SQL Expression">Expression</a>;</pre><p>Any expression can be called like a stored procedure, including,
4574
4740
but not only Java stored procedures or functions. This command returns a
4575
4741
ResultSet with one column and one row (the result) just like a SELECT
4576
4742
statement with one row and one column.</p><p>See also: <a href="#stored-section" title="Stored Procedures / Functions">Stored Procedures / Functions</a>, <a href="#expression-section" title="SQL Expression">SQL Expression</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="checkpoint-section"></a>CHECKPOINT</h3></div></div><div></div></div><pre class="programlisting">CHECKPOINT [DEFRAG<sup>[<a href="#ftn.posthyper">1</a>]</sup>];</pre><p>Closes the database files, rewrites the script file, deletes the
4577
4743
log file and opens the database.</p><p>If DEFRAG is specified, this command also shrinks the .data file
4578
4744
to its minimal size.</p><p>See also: <a href="#shutdown-section" title="SHUTDOWN">SHUTDOWN</a>, <a href="#set_logsize-section" title="SET LOGSIZE">SET LOGSIZE</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="commit-section"></a>COMMIT</h3></div></div><div></div></div><pre class="programlisting">COMMIT [WORK];</pre><p>Ends a transaction and makes the changes permanent.</p><p>See also: <a href="#rollback-section" title="ROLLBACK">ROLLBACK</a>, <a href="#set_autocommit-section" title="SET AUTOCOMMIT">SET AUTOCOMMIT</a>, <a href="#set_logsize-section" title="SET LOGSIZE">SET LOGSIZE</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="connect-section"></a>CONNECT</h3></div></div><div></div></div><pre class="programlisting">CONNECT USER <username> PASSWORD <password>;</pre><p>Connects to the database as a different user. Password should be
4579
4745
double quoted. Use "" for an empty password.</p><p>See also: <a href="#grant-section" title="GRANT">GRANT</a>,
4580
<a href="#revoke-section" title="REVOKE">REVOKE</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="create_alias-section"></a>CREATE ALIAS</h3></div></div><div></div></div><pre class="programlisting">CREATE ALIAS <function> FOR <javaFunction>;</pre><p>Creates an alias for a Java function. The function must be
4581
accessible from the JVM in which the database runs. Example:</p><div class="informalexample"><pre class="programlisting"> CREATE ALIAS ABS FOR "java.lang.Math.abs";</pre></div><p>See also: <a href="#call-section" title="CALL">CALL</a>,
4746
<a href="#revoke-section" title="REVOKE">REVOKE</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="create_alias-section"></a>CREATE ALIAS</h3></div></div><div></div></div><pre class="programlisting">CREATE ALIAS <function> FOR <javaFunction>;</pre><p>Creates an alias for a static Java function to be used as a
4747
<a href="#stored-section" title="Stored Procedures / Functions">Stored Procedure</a>.
4748
The function must be accessible from the JVM in which the database
4749
runs. Example:</p><div class="informalexample"><pre class="programlisting"> CREATE ALIAS ABS FOR "java.lang.Math.abs";</pre></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
4750
The CREATE ALIAS command just defines the alias.
4751
It does not validate existence of the target method or its
4753
To validate the alias, use it.
4754
</p></div><p>See also: <a href="#call-section" title="CALL">CALL</a>,
4582
4755
<a href="#stored-section" title="Stored Procedures / Functions">Stored Procedures / Functions</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="create_index-section"></a>CREATE INDEX</h3></div></div><div></div></div><pre class="programlisting">CREATE [UNIQUE] INDEX <index> ON <table> (<column> [DESC] [, ...]) [DESC];</pre><p>Creates an index on one or more columns in a table.</p><p>Creating an index on searched columns may improve performance. The
4583
4756
qualifier DESC can be present for command compatibility with other
4584
4757
databases but it has no effect. Unique indexes can be defined but this
4585
4758
is deprecated. Use UNIQUE constraints instead. The name of an index must
4586
4759
be unique within the whole database.</p><p>See also: <a href="#create_table-section" title="CREATE TABLE">CREATE TABLE</a>, <a href="#drop_index-section" title="DROP INDEX">DROP INDEX</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="create_role-section"></a>CREATE ROLE<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">CREATE ROLE <rolename>;</pre><p>Creates the named role with no members. Requires Administrative
4587
privileges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11CA5"></a>CREATE SCHEMA<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">CREATE SCHEMA <schemaname> AUTHORIZATION DBA [<createStatement> [<grantStatement<] [...];</pre><p>Creates the named schema.</p><p>Optional (nested) CREATE and GRANT statements can be given only
4760
privileges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="N11D63"></a>CREATE SCHEMA<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">CREATE SCHEMA <schemaname> AUTHORIZATION <grantee>
4761
[<createStatement> [<grantStatement>] [...];</pre><p>Creates the named schema, with ownership of the specified
4762
<span class="emphasis"><em>authorization</em></span>. The authorization grantee may be a
4763
database user or a role.</p><p>Optional (nested) CREATE and GRANT statements can be given only
4588
4764
for new objects in this new schema. Only the last nested statement
4589
4765
should be terminated with a semicolon, because the first semicolon
4590
4766
encountered after "CREATE SCHEMA" will end the CREATE SCHEMA command. In
4591
4767
the example below, a new schema, ACCOUNTS, is created, then two tables
4592
4768
and a view are added to this schma and some rights on these objects are
4593
4769
granted.<div class="informalexample"><pre class="programlisting"> CREATE SCHEMA ACCOUNTS AUTHORIZATION DBA
4594
CREATE TABLE AB(A INTEGER, ...)
4595
CREATE TABLE CD(C CHAHR, ...)
4596
CREATE VIEW VI AS SELECT ...
4597
GRANT SELECT TO PUBLIC ON AB
4598
GRANT SELECT TO JOE ON CD;
4599
</pre></div></p><p>Requires Administrative privileges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="create_sequence-section"></a>CREATE SEQUENCE<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">CREATE SEQUENCE <sequencename> [AS {INTEGER | BIGINT}] [START WITH <startvalue>] [INCREMENT BY <incrementvalue>];</pre><p>Creates a sequence. The default type is INTEGER. The default start
4770
CREATE TABLE AB(A INTEGER, ...)
4771
CREATE TABLE CD(C CHAHR, ...)
4772
CREATE VIEW VI AS SELECT ...
4773
GRANT SELECT TO PUBLIC ON AB
4774
GRANT SELECT TO JOE ON CD;
4776
Note that this example consists of one CREATE SCHEMA statement which
4777
is terminated by a semicolon.
4778
</p><p>Requires Administrative privileges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="create_sequence-section"></a>CREATE SEQUENCE<sup>[<a href="#ftn.posthyper">1</a>]</sup></h3></div></div><div></div></div><pre class="programlisting">CREATE SEQUENCE <sequencename> [AS {INTEGER | BIGINT}]
4779
[START WITH <startvalue>] [INCREMENT BY <incrementvalue>];</pre><p>Creates a sequence. The default type is INTEGER. The default start
4600
4780
value is 0 and the increment 1. Negative values are not allowed. If a
4601
4781
sequence goes beyond Integer.MAXVALUE or Long.MAXVALUE, the next result
4602
4782
is determined by 2's complement arithmetic.</p><p>The next value for a sequence can be included in SELECT, INSERT
4603
4783
and UPDATE statements as in the following example:</p><p>
4604
<div class="informalexample"><pre class="programlisting">SELECT [...,] NEXT VALUE FOR <sequencename> [, ...] FROM <tablename></pre></div>
4784
<div class="informalexample"><pre class="programlisting">SELECT [...,] NEXT VALUE FOR <sequencename> [, ...] FROM <tablename>;</pre></div>
4605
4785
</p><p>In the proposed SQL 200n and in the current version, there is no
4606
4786
way of retreiving the last returned value of a sequence.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="create_table-section"></a>CREATE TABLE</h3></div></div><div></div></div><pre class="programlisting">CREATE [MEMORY | CACHED | [GLOBAL] TEMPORARY | TEMP <sup>[<a href="#ftn.posthyper">1</a>]</sup> | TEXT<sup>[<a href="#ftn.posthyper">1</a>]</sup>] TABLE <name>
4607
( <columnDefinition> [, ...] [, <constraintDefinition>...] ) [ON COMMIT {DELETE | PRESERVE} ROWS];</pre><p>Creates a tables in memory (default) or on disk and only cached in
4787
( <columnDefinition> [, ...] [, <constraintDefinition>...] )
4788
[ON COMMIT {DELETE | PRESERVE} ROWS];</pre><p>Creates a tables in memory (default) or on disk and only cached in
4608
4789
memory. If the database is all-in-memory, both MEMORY and CACHED forms
4609
4790
of CREATE TABLE return a MEMORY table while the TEXT form is not
4610
allowed.</p><div class="variablelist"><p class="title"><b>Components of a CREATE TABLE command</b></p><dl><dt><a name="columnDef-entry"></a><span class="term"><a name="columnDef-title"></a>columnDefinition</span></dt><dd><pre class="programlisting"> columnname <a href="#datatypes-section" title="Data Types">Datatype</a> [(columnSize[,precision])] [{DEFAULT <defaultValue> |
4611
GENERATED BY DEFAULT AS IDENTITY (START WITH <n>[, INCREMENT BY <m>])}] |
4791
allowed.</p><div class="variablelist"><p class="title"><b>Components of a CREATE TABLE command</b></p><dl><dt><a name="columnDef-entry"></a><span class="term"><a name="columnDef-title"></a>columnDefinition</span></dt><dd><pre class="programlisting">columnname <a href="#datatypes-section" title="Data Types">Datatype</a> [(columnSize[,precision])]
4792
[{DEFAULT <defaultValue> |
4793
GENERATED BY DEFAULT AS IDENTITY
4794
(START WITH <n>[, INCREMENT BY <m>])}] |
4612
4795
[[NOT] NULL] [IDENTITY] [PRIMARY KEY]</pre><p>Default values that are allowed are constant values or
4613
4796
certain SQL datetime functions.</p><div class="itemizedlist"><p class="title"><b>Allowed Default Values in Column Definitions</b></p><ul type="disc"><li><p>For character column, a single-quoted string or NULL.
4614
4797
The only SQL function that can be used is CURRENT_USER.</p></li><li><p>For datetime columns, a single-quoted DATE, TIME or
4910
5114
leaving the other part to be performed automatically at the next
4911
5115
startup.</p><p>This command produces a full script of the database which
4912
5116
can be edited for special purposes prior to the next
4913
startup.</p></dd></dl></div><p>Only an administrator may use the SHUTDOWN command.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="update-section"></a>UPDATE</h3></div></div><div></div></div><pre class="programlisting">UPDATE table SET column = Expression [, ...] [WHERE Expression];</pre><p>Modifies data of a table in the database.</p><p>See also: <a href="#select-section" title="SELECT">SELECT<sup>[<a href="#ftn.posthyper">1</a>]</sup></a>, <a href="#insert-section" title="INSERT">INSERT</a>, <a href="#delete-section" title="DELETE">DELETE</a>.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="datatypes-section"></a>Data Types</h2></div></div><div></div></div><div class="table"><a name="N12142"></a><p class="title"><b>Table 9.1. Data Types. The types on the same line are equivalent.</b></p><table summary="Data Types. The types on the same line are equivalent." width="100%" border="1"><colgroup><col><col><col></colgroup><thead><tr><th align="left">Name</th><th align="left">Range</th><th align="left">Java Type</th></tr></thead><tbody><tr><td align="left">INTEGER | INT</td><td align="left">as Java type</td><td align="left"><tt class="literal">int</tt> |
5117
startup.</p></dd></dl></div><p>Only an administrator may use the SHUTDOWN command.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="update-section"></a>UPDATE</h3></div></div><div></div></div><pre class="programlisting">UPDATE table SET column = Expression [, ...] [WHERE Expression];</pre><p>Modifies data of a table in the database.</p><p>See also: <a href="#select-section" title="SELECT">SELECT<sup>[<a href="#ftn.posthyper">1</a>]</sup></a>, <a href="#insert-section" title="INSERT">INSERT</a>, <a href="#delete-section" title="DELETE">DELETE</a>.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="schemanaming-section"></a>Schema object naming</h2></div></div><div></div></div><p><span class="emphasis"><em>Schema</em></span> objects are database objects that are
5118
always scoped to a specific schema. Each schema has a namespace. There may
5119
be multiple schema objects of the same name, each in the namespace of a
5120
different schema. A particular schema object may nearly always be uniquely
5121
identified using the notation <tt class="literal">schemaname.objectname</tt>.
5122
All HSQLDB database objects are schema objects, other than the
5123
following.</p><table summary="Simple list" border="0" class="simplelist"><tr><td>
5128
<p>Store Procedure Java Classes</p>
5131
</td></tr></table><p>Our current Java-class-based Triggers are not fully schema
5132
objects. However, we are in the process of implementing SQL-conformant
5133
triggers which will encompass our Java-class-based triggers. When this
5134
work is completed, HSQLDB triggers will be schema objects.</p><p>Sequences are schema objects with creation and removal permission
5135
governed by schema authorization (as described hereafter), but GRANT
5136
and REVOKE command do not work yet for sequences.
5137
In a future version of HSQLDB, sequence GRANTs and REVOKEs will work
5138
similarly to the current GRANT and REVOKE commands for table access.
5139
</p><p>Most of the time, you do not need to specify the schema for the
5140
desired schema object, because the implicit schema is usually the only one
5141
that can be used. For example, when creating an index, the target schema
5142
will default to that of the table which is the target of the index. Named
5143
constraints are an extreme example of this. There is never a need to
5144
specify a schema name for a constraint, since constraint names are only
5145
specified in a CREATE or ALTER TABLE command, and the schema must be that
5146
of the target table. If the implicit schema is not determined by a related
5147
object, then the default comes from your JDBC session's current schema
5148
setting. The session schema value will be your login user's
5149
<span class="emphasis"><em>initial schema</em></span>, or whatever you last set it to with
5150
<a href="#set_schema-section" title="SET SCHEMA">SET SCHEMA<sup>[<a href="#ftn.posthyper">1</a>]</sup></a> in your
5151
<span class="emphasis"><em>current</em></span> JDBC session with the SET SCHEMA command.
5152
(Your initial schema is "PUBLIC" unless changed with the <a href="#alter_user-section" title="ALTER USER"> ALTER USER SET INITIAL SCHEMA</a> or the
5153
<a href="#set_initialschema-section" title="SET INITIAL SCHEMA ">SET INITIAL SCHEMA <sup>[<a href="#ftn.posthyper">1</a>]</sup></a> command).</p><p>In addition to namespace scoping, there are permission aspects to
5154
the schema of a database object. The <span class="emphasis"><em>authorization</em></span> of
5155
a schema is a role or user that is basically the
5156
<span class="emphasis"><em>owner</em></span> of the schema. Only a user with the DBA role
5157
(an admin user) or the owner of a schema may create objects, or modify the
5158
DDL of objects, in the namespace of that schema. In this way, a schema
5159
authorization is said to "own" the objects of that schema. A schema
5160
authorization/owner can be a role or a user (even a role with no members).
5161
The two schemas automatically created when a database is initialized are
5162
both owned by the role <span class="emphasis"><em>DBA</em></span>.</p><p>An important implication to database objects being
5163
<span class="emphasis"><em>owned</em></span> by the schema owner is, if a non-DBA database
5164
user is to have permission to create any database object, they must have
5165
ownership of a schema. To allow a user to create (or modify DDL of)
5166
objects in their own personal schema, you would create a new schema with
5167
that user as the authorization. To allow a non-DBA user to share create
5168
and DDL privileges in some schema, you would create this schema with
5169
a role as the authorization, then GRANT this role to all of the desired
5170
users.</p><p>The INFORMATION_SCHEMA is a system defined schema that contains
5171
the system tables for the database. This schema is read-only. When a
5172
database is created, a shema named PUBLIC is automatically created as the
5173
default schma. This schema has the authorization DBA. You can change the
5174
name of this schema. If all non-system schemas are dropped from a
5175
database, an empty PUBLIC schema is created again. So each database always
5176
has at least one non-system schema.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="datatypes-section"></a>Data Types</h2></div></div><div></div></div><div class="table"><a name="N12272"></a><p class="title"><b>Table 9.1. Data Types. The types on the same line are equivalent.</b></p><table summary="Data Types. The types on the same line are equivalent." width="100%" border="1"><colgroup><col><col><col></colgroup><thead><tr><th align="left">Name</th><th align="left">Range</th><th align="left">Java Type</th></tr></thead><tbody><tr><td align="left">INTEGER | INT</td><td align="left">as Java type</td><td align="left"><tt class="literal">int</tt> |
4914
5177
<tt class="classname">java.lang.Integer</tt></td></tr><tr><td align="left">DOUBLE [PRECISION] | FLOAT</td><td align="left">as Java type</td><td align="left"><tt class="literal">double</tt> |
4915
5178
<tt class="classname">java.lang.Double</tt></td></tr><tr><td align="left">VARCHAR</td><td align="left">as Integer.MAXVALUE</td><td align="left"><tt class="classname">java.lang.String</tt></td></tr><tr><td align="left">VARCHAR_IGNORECASE</td><td align="left">as Integer.MAXVALUE</td><td align="left"><tt class="classname">java.lang.String</tt></td></tr><tr><td align="left">CHAR | CHARACTER</td><td align="left">as Integer.MAXVALUE</td><td align="left"><tt class="classname">java.lang.String</tt></td></tr><tr><td align="left">LONGVARCHAR</td><td align="left">as Integer.MAXVALUE</td><td align="left"><tt class="classname">java.lang.String</tt></td></tr><tr><td align="left">DATE</td><td align="left">as Java type</td><td align="left"><tt class="classname">java.sql.Date</tt></td></tr><tr><td align="left">TIME</td><td align="left">as Java type</td><td align="left"><tt class="classname">java.sql.Time</tt></td></tr><tr><td align="left">TIMESTAMP | DATETIME</td><td align="left">as Java type</td><td align="left"><tt class="classname">java.sql.Timestamp</tt></td></tr><tr><td align="left">DECIMAL</td><td align="left">No limit</td><td align="left"><tt class="classname">java.math.BigDecimal</tt></td></tr><tr><td align="left">NUMERIC</td><td align="left">No limit</td><td align="left"><tt class="classname">java.math.BigDecimal</tt></td></tr><tr><td align="left">BOOLEAN | BIT</td><td align="left">as Java type</td><td align="left"><tt class="literal">boolean</tt> |
4916
5179
<tt class="classname">java.lang.Boolean</tt></td></tr><tr><td align="left">TINYINT</td><td align="left">as Java type</td><td align="left"><tt class="literal">byte</tt> |