Small. Fast. Reliable.
Choose any three.

SQLite Language Syntax Requirements

These requirements make the distinction between "preparing" an SQL statement and "evaluating" or "invoking" an SQL statement. Preparation means that the SQL statement text is translated into an internal binary representation that is more suitable for processing. Evaluation or invocation means that the processing is actually carried out. Preparation of an SQL statement is usually accomplished by interfaces sqlite3_prepare(), sqlite3_prepare16(), or sqlite3_prepare_v2() and evaluation or invocation of an SQLite statement is accomplished by calling sqlite3_step(). However, if a statement is initially prepared using sqlite3_prepare_v2() and a change to the database schema is detected during evaluation, then the preparation is redone automatically, by sqlite3_step(). So even though it is reasonable to think about preparation as being a function of sqlite3_prepare_v2() and its companions and evaluation as being a function of sqlite3_step(), the reader should keep in mind that sqlite3_step() might also sometimes do preparations following schema changes.

1.0 General Requirements

1.1 Parser operation

SQLite expects all statements to be terminated by a semicolon. If a statement is submitted to SQLite that does not end in a semicolon, then a semicolon is added automatically by the tokenizer. (See H41040.)

H42000: The SQLite parser shall accept SQL statements consisting of an SQL command followed by a semicolon.
sql_statement ::= cmd SEMI.

Acceptance by the parser does not imply that the SQL statement will be accepted by SQLite. SQL statements may be rejected by other parts of the SQLite library. Acceptance by the parser is a necessary but not a sufficient condition for the statement to work.

H42002: The preparation of an SQL statement that is not accepted by the SQLite parser shall fail with an error.

SQLite ignores case when comparing ASCII characters in identifiers and in type names. (The rules for comparison of content are different.) Case is considered for other unicode characters, however. Hence, SQLite considers identifiers "A" and "a" to be equivalent but "Å" and "å" are distinct.

H42004: SQLite shall use the built-in NOCASE collating sequence when comparing identifiers and datatype names within SQL statements during statement preparation.

Many tokens are allowed to "fallback" to the ID token. The SQL language has many keywords. The fallback token feature provides robustness in the case where a seldom-used keyword is accidentally used as the name of a table or column.

H42008: A token received by the parser shall be converted into an ID token if the original token value would have resulted in a syntax error, a token value of ID will allow the parse to continue, and if the original token value was one of: ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT CTIME_KW DATABASE DEFERRED DESC DETACH EACH END EXCEPT EXCLUSIVE EXPLAIN FAIL FOR IF IGNORE IMMEDIATE INITIALLY INSTEAD INTERSECT KEY LIKE_KW MATCH OF OFFSET PLAN PRAGMA QUERY RAISE REINDEX RENAME REPLACE RESTRICT ROW TEMP TRIGGER UNION VACUUM VIEW VIRTUAL

A second level of fallback allows any token to be converted into the token ANY. The ANY token is used to gather arbitrary delimited token sequences, such as used as the arguments to the CREATE VIRTUAL TABLE command.

H420012: A token received by the parser shall be converted into an ANY token if the original token value would have resulted in a syntax error and if a token value of ANY will allow the parse to continue.

1.2 Name Contexts

Expressions in SQL statements often contain identifiers that refer to columns in tables or views or to columns in the result set of a SELECT statement. The process of determining which column an identifier refers to is called "name resolution".

Names are resolved with the aid of a "name context". A name context is a set of tables and views and result set expressions to which an expression identifier can refer. A single name context is a hierarchy of "name context layers". Subqueries have their own name context layer (called the "inner layer") that is distinct from the name context layer (called the "outer layer") associated with the overall statement. In an SQL statement with multiple levels of tested subqueries, there can be multiple name context layers in the name context. In other words, a complete name context is an ordered list of name context layers.

Within a name context a "source" is a table or view containing columns that expression names can match against. Every source has a "canonical name" which is the name of the table or view as it appears in the schema. A source might also have an "aliased name" resulting from an AS clause. The "source name" is the aliased name if it exists, otherwise the source name is the canonical name.

Each name context layer has a "source set" and a "result set", either or both of which can be empty. The source set is an ordered set of sources. The result set is an ordered set of expressions with an optional alias on each expression. Roughly speaking, a source set corresponds to the FROM clause of a SELECT statement and the result set corresponds to the list of expressions that form the result set of the SELECT statement.

A "empty name context" is a name context comprised of a single name context layer in which both the source set and the result set are empty.

2.0 Transaction Control

2.1 BEGIN

H42010: The SQLite parser shall accept BEGIN statements that conform to the following syntax:
cmd ::= BEGIN transaction_type transaction_name.
transaction_type ::= .
transaction_type ::= DEFERRED.
transaction_type ::= IMMEDIATE.
transaction_type ::= EXCLUSIVE.
transaction_name ::= .
transaction_name ::= TRANSACTION.
transaction_name ::= TRANSACTION name.
H42013: The successful evaluation of a BEGIN statement shall cause the database connection to exit autocommit mode.
H42016: The evaluation of a BEGIN TRANSACTION statement shall fail with an error if the database connection is not in autocommit mode at the start of evaluation.
H42019: If the transaction_type keyword is omitted from a BEGIN TRANSACTION statement then the behavior shall be the same as if the DEFERRED keyword were used.
H42022: When the DEFERRED keyword appears in a BEGIN statement the locking state of the underlying database files shall be the same before and after the statement is evaluated.
H42025: When the IMMEDIATE keyword appears in a BEGIN statement then successful evaluation of the statement shall cause a RESERVED lock to be obtained for all underlying database files.
H42028: When the EXCLUSIVE keyword appears in a BEGIN statement then successful evaluation of the statement shall cause a EXCLUSIVE lock to be obtained for all underlying database files.

The transaction_name clause of a BEGIN statement is provided for syntactic compatibility to other SQL database engines. The transaction_name clause is silently ignored.

2.2 COMMIT

H42110: SQLite shall accept the following COMMIT statement syntax:
cmd ::= COMMIT transaction_name.
cmd ::= END transaction_name.
H42113: The successful evaluation of COMMIT statement places the database connection in autocommit mode.
H42116: If a database connection is already in autocommit mode when a COMMIT statement is evaluated, then the statement shall fail with an error.

The transaction_name clause of a COMMIT statement is provided for syntactic compatibility to other SQL database engines. The transaction_name clause is silently ignored.

The COMMIT and END statements are aliases for one another and accomplish exactly the same thing. One is merely a different way of expression the other.

2.3 ROLLBACK

H42210: The SQLite parser shall accept ROLLBACK statements that conform to the following syntax:
cmd ::= ROLLBACK transaction_name.
H42213: The successful evaluation of ROLLBACK statement places the database connection in autocommit mode.
H42216: If a database connection is already in autocommit mode when a ROLLBACK statement is invoked, then the statement invocation shall fail with an error.

A "pending statement" is a statement for which sqlite3_step() has been called at least once without a subsequent call to either sqlite3_reset() or sqlite3_finalize().

H42222: Other pending statements on the same database connection as a successfully evaluated ROLLBACK statement shall be aborted.
H42225: The successful evaluation of a ROLLBACK statement causes the current transaction on the database connection to roll back.

The transaction_name clause of a BEGIN statement is provided for syntactic compatibility to other SQL database engines. The transaction_name clause is silently ignored.

3.0 Data Definition Language (DDL)

3.1 CREATE TABLE

H42310: The SQLite parser shall accept CREATE TABLE statements that conform to the following syntax:
cmd ::= CREATE temp TABLE ifnotexists fullname table_definition.
temp ::= .
temp ::= TEMP.
ifnotexists ::= .
ifnotexists ::= IF NOT EXISTS.

The fullname non-terminal symbol of the SQLite grammar specifies an SQL object contained within a particular database file. A specific database might be stated explicitly: <fullname ::= databasename DOT objectname.> or the database might be implied: <fullname ::= objectname.>. An unspecified databasename has a default value that depends on context and which is specified by requirements.

H42313: When the TEMP keyword appears in a CREATE TABLE statement and the databasename exists and is something other than "temp", then the preparation of the CREATE TABLE statement shall fail with an error.
H42316: When the TEMP keyword appears in a CREATE TABLE statement the behavior shall be as if the databasename where "temp".
H42319: The successful evaluation of a CREATE TABLE statement shall cause a new SQL table whose name is given by the objectname to be created in the schema of the database whose name is given by the databasename.
H42322: If a CREATE TABLE statement specifies no databasename and omits the TEMP keyword then the behavior shall be as if a databasename of "main" where used.
H42325: The preparation of a CREATE TABLE statement shall fail with an error if the IF NOT EXISTS clause is omitted and the objectname is the same as the name of a table or view in the same database.
H42328: The evaluation of a CREATE TABLE statement shall be a silent no-op if the IF NOT EXISTS clause is present and the objectname is the same as the name of a table or view in the same database.
H42331: The preparation of a CREATE TABLE statement shall fail with an error if the the objectname is the same as the name of an index in any database attached to the same database connection.
H42334: The preparation of a CREATE TABLE statement shall fail with an error if the the databasename references a database that is not attached to the same database connection.

3.1.1 CREATE TABLE column definitions

There are two varieties of CREATE TABLE statements. The most common form specifies the names of all columns in the table together with datatype and constraint information. This first form is called a "ordinary CREATE TABLE statement". The second form of CREATE TABLE constructs a new table from the result set of a SELECT statement. The second form is called a "CREATE TABLE AS statement".

In an ordinary CREATE TABLE statement, the table_definition consists of a list of column definitions optionally followed by a list of table constraints.

H42410: The SQLite parser shall accept the following syntax for the table_definition section of a CREATE TABLE statement:
table_definition ::= LP columnlist constraint_opt RP.
columnlist ::= column.
columnlist ::= columnlist COMMON column.
constraint_opt ::= .
constraint_opt ::= COMMA constraint_list.

A column definition within an ordinary CREATE TABLE statement always has a column name. It might also include a datatype for the column and zero or more contraints on the column. But both the datatype and the constraints are options. Other SQL database engines also have optional constraints but they usually make the datatype required.

H42413: The SQLite parser shall accept the following syntax for the column component of a table_definition.
column ::= name column_type column_constraint_list.
column_type ::= .
column_type ::= typename.
column_type ::= typename LP signed_int RP.
column_type ::= typename LP signed_int COMMA signed_int RP.
typename ::= identifier.
typename ::= typename identifier.
signed_int ::= INTEGER.
signed_int ::= MINUS INTEGER.
signed_int ::= PLUS INTEGER.
H42416: The preparation of an ordinary CREATE TABLE statement shall fail with an error if it specifies two or more columns with the same name.
H42419: The datatype affinity of each column in a table generate by an ordinary CREATE TABLE statement shall be determined from the column_type text using the following 5-step algorithm:
  1. If the column_type contains the string "INT" then the affinity is INTEGER.

  2. Else if the column_type contains one of the strings "CHAR", "CLOB", or "TEXT" then the affinity is TEXT.

  3. Else if the column_type contains the string "BLOB" or is omitted then the affinity is NONE.

  4. Else if the column_type constains one of the strings "REAL", "FLOA", or "DOUB" then the affinity is REAL.

  5. Otherwise the affinity is NUMERIC.

H42450: The SQLite parser shall accept the following syntax for the list of column constraints and modifiers that follows a column definition in an ordinary CREATE TABLE statement.
column_constraint_list ::= .
column_constraint_list ::= column_constraint_list named_column_constraint.
named_column_constraint ::= CONSTRAINT name column_constraint.
named_column_constraint ::= column_constraint.
column_constraint ::= DEFAULT term.
column_constraint ::= DEFAULT identifier.
column_constraint ::= DEFAULT PLUS term.
column_constraint ::= DEFAULT MINUS term.
column_constraint ::= DEFAULT LP expr RP.
column_constraint ::= NULL conflict.
column_constraint ::= NOT NULL conflict.
column_constraint ::= PRIMARY KEY sortorder conflict autoincr.
column_constraint ::= UNIQUE conflict.
column_constraint ::= CHECK LP expr RP.
column_constraint ::= COLLATE identifier.
column_constraint ::= foreign_key_constraint.
column_constraint ::= deferrable_constraint.
autoincr ::= .
autoincr ::= AUTOINCR.
indexlist_opt ::= .
indexlist_opt ::= LP indexlist RP.
conflict ::= .
conflict ::= ON CONFLICT IGNORE.
conflict ::= ON CONFLICT REPLACE.
conflict ::= ON CONFLICT ABORT.
conflict ::= ON CONFLICT FAIL.
conflict ::= ON CONFLICT ROLLBACK.
H42453: When a column as a DEFAULT constraint, the default value for the column shall be the value specified by that constraint.
H42456: If a column has no DEFAULT constraint then the default value for that column shall be NULL.

Every column a table has a "null-conflict resolution behavior" which is one of NONE, IGNORE, REPLACE, FAIL, ABORT, or ROLLBACK.

The default null-conflict resolution behavior is NONE, which means NULLs are allowed in the column. This can be made explicit by specifying the NULL constraint. But the use of the NULL constraint is merely a comment for human readers. SQLite silently ignores the NULL constraint and its ON CONFLICT clause. SQLite only cares about NOT NULL constraints since only NOT NULL constraints make a behaviorial difference.

H42459: If a column has no NOT NULL constraint then the NULL conflict resolution behavior for the column shall be NONE.
H42462: If a column has a NOT NULL constraint and that constrait lacks an ON CONFLICT clause then the null-conflict resolution behavior for the column shall be ABORT.
H42465: If a column has a NOT NULL constraint and that constraint has an ON CONFLICT clause then the null-conflict resolution behavior for the column shall be the behavior specified by the ON CONFLICT clause.
H42467: A column without a COLLATE constraint shall have a default collating sequence of BINARY.
H42468: A column with a COLLATE constraint shall have a default collating sequence as specified by the COLLATE constraint.

The rowid is the underlying key used for storing each row of a table in the B-Tree that implements that table. Every table has a rowid column which is either implicit or explicit. There can be up to four names for the rowid within the same table. All can be used interchangeably.

H42470: If the datatype of a single-column PRIMARY KEY is exactly "INTEGER" then the name of that column shall be an alias for the table rowid.
H42472: If a table contains no column named "ROWID" then "ROWID" shall be an alias for the table rowid.
H42474: If a table contains no column named "OID" then "OID" shall be an alias for the table rowid.
H42476: If a table contains no column named "_ROWID_" then "_ROWID_" shall be an alias for the table rowid.

The AUTOINCREMENT keyword is ignored except when it appears on an explicit rowid column.

H42478: A table shall have an autoincrementing rowid if and only if the PRIMARY KEY for the table is an alias for the rowid and the PRIMARY KEY declaration uses the AUTOINCR keyword.
H42480: Successful evaluation of a CREATE TABLE statement shall create an index for every UNIQUE constraint where the created index has a conflict resolution algorithm as specified by the ON CONFLICT clause of the UNIQUE constraint or a conflict resolution algorithm of ABORT if there is no ON CONFLICT clause on the constraint.
H42510: The SQLite parser shall accept the following syntax for the list of table contraints that occurs at the end of an ordinary CREATE TABLE statement.
constraint_list ::= constraint.
constraint_list ::= constraint_list constraint.
constraint_list ::= constraint_list COMMA constraint.
constraint ::= CHECK LP expr RP conflict.
constraint ::= CONSTRAINT name.
constraint ::= FOREIGN KEY LP columnlist RP foreign_key_constraint defer_opt.
constraint ::= PRIMARY KEY LP indexlist autoinc RP conflict.
constraint ::= UNIQUE LP indexlist RP conflict.
H42513: The preparation of a CREATE TABLE statement that contains more than one PRIMARY KEY constraint shall fail with an error.
H42516: The preparation of a CREATE TABLE statement that contains a CHECK constraint that uses a subquery shall fail with an error.
H42517: The preparation of a CREATE TABLE statement that contains a CHECK constraint that uses a parameter shall fail with an error.
H42518: Name resolution of the expr with each CHECK constraint of a CREATE TABLE statement shall be carried out using a name context with an empty result set and a source set holding single source element that is the table being created.
H42521: The preparation of a CREATE TABLE statement that contains a DEFAULT constraint with an non-constant expression shall fail with an error.

Except for the special case of INTEGER PRIMARY KEY, a PRIMARY KEY is just an alias for UNIQUE.

H42536: A PRIMARY KEY constraint that does not result in a rowid alias shall have the same effect as a UNIQUE constraint.
H42539: Preparation of a CREATE TABLE statement shall fail with an error if the indexlist of either a table PRIMARY KEY or a table UNIQUE constraint references a column that is not a column in the table.

Foreign key constraints are parsed for compatibility with other database engines but are not enforced by SQLite.

H42570: The SQLite parser shall accept the following syntax for a foreign key constraint as either a separate constraint or as part of a column constraint in an ordinary CREATE TABLE statement.
foreign_key_constraint ::= REFERENCES name indexlist_opt fkarglist.
defer_opt ::= .
defer_opt ::= deferrable_constraint.
deferrable_constraint ::= NOT DEFERRABLE initially_deferred_clause.
deferrable_constraint ::= DEFERRABLE initially_deferred_clause.
fkarglist ::= .
fkarglist ::= fkarglist fkarg.
fkarg ::= MATCH name.
fkarg ::= ON DELETE fkaction.
fkarg ::= ON UPDATE fkaction.
fkarg ::= ON INSERT fkaction.
fkaction ::= SET NULL.
fkaction ::= SET DEFAULT.
fkaction ::= CASCADE.
fkaction ::= RESTRICT.
initially_deferred_clause ::= .
initially_deferred_clause ::= INITIALLY DEFERRED.
initially_deferred_clause ::= INITIALLY IMMEDIATE.

3.1.2 CREATE TABLE AS

The CREATE TABLE AS statement generates a new table to hold the result set of a SELECT statement.

H42610: The SQLite parser shall accept the following syntax for creating new database tables from the result set of SELECT statements.
table_definition ::= AS select.

The names of the columns in the generated table are taken from the column names of the SELECT statement. All other attributes of the generated table are the default attributes for a column. Hence, the table generated by a CREATE TABLE AS as the same behavior as an ordinary CREATE TABLE where the table_definition consists of a comma-separated list of column names with no datatypes or constraints of any kind.

H42613: The table generated by a CREATE TABLE AS statement shall have the same number of columns as the result set of the SELECT.
H42616: The names of the columns in a table generated by a CREATE TABLE AS statement shall have base names which are the names of the columns in the result set of the SELECT statement
H42617: Each column name in a table generated by a CREATE TABLE AS statement shall have an arbitrary suffix appended to its basename if and only if such a suffix is necessary to make the name distinct from all preceding column names in the table.
H42619: All columns in a table generated by a CREATE TABLE AS statement shall have a default value of NULL.
H42622: All columns in a table generated by a CREATE TABLE AS statement shall have a NULL conflict resolution behavior of NONE.
H42625: All columns in a table generated by a CREATE TABLE AS statement shall have an affinity of NONE.
H42628: All columns in a table generated by a CREATE TABLE AS statement shall have a default collating sequence of BINARY.

3.2 DROP TABLE

H42700: The SQLite parser shall accept DROP TABLE statements that conform to the following syntax.
cmd ::= DROP TABLE ifexists fullname.
ifexists ::= .
ifexists ::= IF EXISTS.
H42710: The preparation of a DROP TABLE statement shall fail with an error if the statement lacks an IF EXISTS clause and the fullname does not reference a existing table.
H42713: The evaluation of a DROP TABLE statement shall be a silent no-op if the the statement has an IF EXISTS clause and the fullname does not reference a existing table.
H42716: The successful evaluation of a DROP TABLE statement shall cause the table identified by fullname to be removed from its database and discarded.
H42719: The successful evaluation of a DROP TABLE statement shall cause all indices attached to the table identified by fullname to be removed from their database and discarded.
H42721: The successful evaluation of a DROP TABLE statement shall cause all triggers attached to the table identified by fullname to be removed from their database and discarded.
H42724: The preparation of a DROP TABLE statement shall fail with an error if fullname is a system table.

3.3 CREATE INDEX

H42800: The SQLite parser shall accept CREATE INDEX statements that conform to the following syntax:
cmd ::= CREATE unique INDEX ifnotexists fullname ON tablename LP indexlist RP.
tablename ::= name.
indexlist ::= indexlist COMMA columnname collate sortorder.
indexlist ::= columnname collate sortorder.
columnname ::= name.
collate ::= .
collate ::= COLLATE identifier.
sortorder ::= .
sortorder ::= ASC.
sortorder ::= DESC.
H42803: The target database of a CREATE INDEX statement shall be the databasename specified in the fullname term of the statement if the databasename exists.
H42806: If the fullname term of a CREATE INDEX statement does not specify a databasename and the tablename references a table that is in the "temp" database, then the target database for the statement shall be "temp".
H42809: If the fullname term of a CREATE INDEX statement does not specify a databasename and the tablename references a table that is not in the "temp" database, then the target database for the statement shall be "main".
H42812: The preparation of a CREATE INDEX statement shall fail with an error if the databasename of the fullname exists and references a database that is not attached to the same database connection.
H42815: The preparation of a CREATE INDEX statement shall fail with an error if the tablename does not reference an ordinary table in the database of the statement.
H42818: A successful evaluation of a CREATE INDEX statement shall create a new index called objectname in the database of the statement and attached to the table identified by tablename in that same database.
H42821: An index generated by a CREATE INDEX statement that omits the UNIQUE keyword shall have a conflict resolution behavior of NONE.
H42824: An index generated by a CREATE INDEX statement that includes the UNIQUE keyword shall have a conflict resolution behavior of ABORT.
H42830: The preparation of a CREATE INDEX statement shall fail with an error if any columnname value within the indexlist is not the name of one of the columns of the tablename table.

The following rules regarding default collating sequences and sort order for indices applies both to indices created by CREATE INDEX statements and also by UNIQUE or PRIMARY KEY constraints on the table definition.

H42833: The collating sequence for each column of an index shall be the collating sequence specified in the indexlist.
H42836: If an index column does not specify a collating sequence then the collating sequence shall be the default collating sequence of the corresponding table column.
H42839: The sort order for an index column shall be descending if and only if the DESC keyword is used in the indexlist entry for that term.
H42842: The preparation of a CREATE INDEX statement shall fail with an error if the tablename refers to a system table.

3.4 DROP INDEX

H42900: The SQLite parser shall accept DROP INDEX statements that conform to the following syntax:
cmd ::= DROP INDEX ifexists fullname.
H42910: The preparation of a DROP INDEX statement shall fail with an error if the statement lacks an IF EXISTS clause and the fullname does not reference a existing index.
H42913: The evaluation of a DROP INDEX statement shall be a silent no-op if the the statement has an IF EXISTS clause and the fullname does not reference a existing index.
H42916: The successful evaluation of a DROP INDEX statement shall cause the index identified by fullname to be removed from its database and discarded.

3.5 CREATE VIEW

H43100: The SQLite parser shall accept CREATE VIEW statements that conform to the following syntax:
cmd ::= CREATE temp VIEW ifnotexists fullname AS select.
H43113: When the TEMP keyword appears in a CREATE VIEW statement and the databasename exists and is something other than "temp", then the preparation of the CREATE VIEW statement shall fail with an error.
H43116: When the TEMP keyword appears in a CREATE VIEW statement the behavior shall be as if the databasename where "temp".
H43119: The successful evaluation of a CREATE VIEW statement shall cause a new view whose name is given by the objectname and is located in the schema of the database whose name is given by the databasename.
H43122: If a CREATE VIEW statement specifies no databasename and omits the TEMP keyword then the behavior shall be as if a databasename of "main" where used.
H43125: The preparation of a CREATE VIEW statement shall fail with an error if the IF NOT EXISTS clause is omitted and the objectname is the same as the name of a table or view in the same database.
H43128: The evaluation of a CREATE VIEW statement shall be a silent no-op if the IF NOT EXISTS clause is present and the objectname is the same as the name of a table or view in the same database.
H43131: The preparation of a CREATE VIEW statement shall fail with an error if the the objectname is the same as the name of an index in any database attached to the same database connection.
H43234: The preparation of a CREATE VIEW statement shall fail with an error if the the databasename references a database that is not attached to the same database connection.
H43237: The view generated by a CREATE VIEW statement shall have the same number of columns as the result set of the SELECT.
H43241: The names of the columns in a view generated by a CREATE VIEW statement shall have base names which are the names of the columns in the result set of the SELECT statement
H43244: Each column name in a table generated by a CREATE VIEW statement shall have an arbitrary suffix appended to its basename if and only if such a suffix is necessary to make the name distinct from all preceding column names in the view.

3.6 DROP VIEW

H43200: The SQLite parser shall accept DROP VIEW statements that conform to the following syntax:
cmd ::= DROP VIEW ifexists fullname.
H43204: The preparation of a DROP VIEW statement shall fail with an error if the statement lacks an IF EXISTS clause and the fullname does not reference a existing view.
H43207: The evaluation of a DROP VIEW statement shall be a silent no-op if the the statement has an IF EXISTS clause and the fullname does not reference a existing view.
H43211: The successful evaluation of a DROP VIEW statement shall cause the view identified by fullname to be removed from its database and discarded.
H43214: The successful evaluation of a DROP VIEW statement shall cause all triggers attached to the view identified by fullname to be removed from their database and discarded.

3.7 CREATE TRIGGER

H43300: The SQLite parser shall accept CREATE TRIGGER statements that conform to the following syntax:
cmd ::= CREATE temp TRIGGER ifnotexists fullname trigger trigger_body.
trigger ::= trigger_time trigger_event foreach_clause when_clause.
trigger_body ::= BEGIN trigger_cmd_list END.
trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI.
trigger_cmd_list ::= trigger_cmd_list.
trigger_cmd ::= DELETE FROM tablename where.
trigger_cmd ::= update_cmd tablename SET setlist where.
trigger_cmd ::= insert_cmd INTO tablename columnlist_opt VALUES LP exprlist RP.
trigger_cmd ::= insert_cmd INTO tablename columnlist_opt select.
trigger_cmd ::= select.
trigger_event ::= DELETE ON trigger_target.
trigger_event ::= INSERT ON trigger_target.
trigger_event ::= UPDATE OF columnlist ON trigger_target.
trigger_event ::= UPDATE ON trigger_target.
trigger_target ::= fullname.
trigger_time ::= AFTER.
trigger_time ::= BEFORE.
trigger_time ::= INSTEAD OF.
trigger_time ::=.
foreach_clause ::= FOR EACH ROW.
foreach_clause ::=.
when_clause ::= WHEN expr.
when_clause ::=.
H43303: When the TEMP keyword appears in a CREATE TRIGGER statement and the databasename of the fullname exists then the preparation of the statement shall fail with an error.
H43306: When the TEMP keyword appears in a CREATE TRIGGER statement the target database of the trigger shall be "temp".
H43309: When the TEMP keyword is omitted in a CREATE TRIGGER statement and the databasename of the fullname is omitted then the target database of the trigger shall be "main".
H43312: When the databasename of fullname in a CREATE TRIGGER statement exists, then the target database shall be the database named by databasename.
H43315: If a CREATE TRIGGER does not specify a trigger_time then the trigger_time shall be BEFORE.

An INSTEAD OF trigger may be used only on views. Other kinds of triggers may be used on tables only.

H43318: The preparation of a CREATE TRIGGER statement shall fail with an error the trigger_time is INSTEAD OF and trigger_target is not the name of view in the target database.
H43321: The preparation of a CREATE TRIGGER statement shall fail with an error the trigger_time is not INSTEAD OF and trigger_target is not the name of an ordinary table in the target database.
H43324: The preparation of a CREATE TRIGGER statement shall fail with an error if the trigger_target is a system table.

3.8 DROP TRIGGER

H43500: The SQLite parser shall accept DROP TRIGGER statements that conform to the following syntax:
cmd ::= DROP TRIGGER ifexists fullname.
H43504: The preparation of a DROP TRIGGER statement shall fail with an error if the statement lacks an IF EXISTS clause and the fullname does not reference a existing trigger.
H43507: The evaluation of a DROP TRIGGER statement shall be a silent no-op if the the statement has an IF EXISTS clause and the fullname does not reference a existing trigger.
H43511: The successful evaluation of a DROP TRIGGER statement shall cause the trigger identified by fullname to be removed from its database and discarded.
H43514: The successful evaluation of a DROP TRIGGER statement shall cause all triggers attached to the trigger identified by fullname to be removed from their database and discarded.

3.9 CREATE VIRTUAL TABLE

H43600: The SQLite parser shall accept CREATE VIRTUAL TABLE statements that conform to the following syntax.
cmd ::= CREATE VIRTUAL TABLE fullname USING name vtab_arg_list.
vtab_arg_list ::= .
vtab_arg_list ::= LP vtab_arg_token RP.
vtab_arg_token ::= ANY.
vtab_arg_token ::= LP anylist RP.
anylist ::= .
anylist ::= anylist ANY.

3.10 ALTER TABLE

3.11 ALTER TABLE RENAME

H43700: The SQLite parser shall accept ALTER TABLE RENAME statements that conform to the following syntax:
cmd ::= ALTER TABLE fullname RENAME TO name.

3.12 ALTER TABLE ADD COLUMN

H43750: The SQLite parser shall accept ALTER TABLE ADD COLUMN statements that conform to the following syntax:
cmd ::= ALTER TABLE fullname ADD column_keyword column.
column_keyword ::= .
column_keyword ::= COLUMNKW.

4.0 Data Manipulation Language (DML)

4.1 INSERT

H43810: The SQLite parser shall accept INSERT statements that conform to the following syntax:
cmd ::= insert_cmd INTO fullname columnlist_opt insert_content.
insert_cmd ::= INSERT.
insert_cmd ::= REPLACE.
insert_cmd ::= INSERT OR REPLACE.
insert_cmd ::= INSERT OR IGNORE.
insert_cmd ::= INSERT OR ABORT.
insert_cmd ::= INSERT OR FAIL.
insert_cmd ::= INSERT OR ROLLBACK.
columnlist_opt ::= .
columnlist_opt ::= LP columnlist RP.
columnlist ::= columnname.
columnlist ::= columnlist COMMA columnname.
H43813: The preparation of an INSERT statement shall fail with an error if the instcolist contains a reference to a column which is not a column in the table identified by fullname and is not one of the special column named "ROWID", "OID", or "_ROWID_".
H43816: The preparation of an INSERT statement shall fail with an error if fullname does not identify either a view with an INSTEAD OF INSERT trigger or a table.
H43819: The preparation of an INSERT statement shall fail with an error if the objectname of the fullname is "sqlite_master" or "sqlite_temp_master" and the database connection is not in writeable schema mode.
H43821: When the form of an INSERT statement is simply "INSERT" then the default null- and uniqueness-conflict resolution algorithms shall be used.
H43824: When the form of an INSERT statement is simply "REPLACE" then the null- and uniqueness-conflict resolution algorithms shall all change to REPLACE.
H43827: When the form of an INSERT statement is "INSERT OR algorithm" then the null- and uniqueness-conflict resolution algorithms shall all change to algorithm.
H43831: Name resolution in the insert_content term of an INSERT statement shall be carried out using a name context with an empty result set and a source set holding single source element that is the fullname table.

4.1.1 INSERT VALUE

H43840: The SQLite parser shall accept INSERT VALUE statements that conform to the following syntax:
insert_content ::= VALUES LP exprlist RP.
H43843: The preparation of an INSERT VALUE statement shall fail with an error if the columnlist element exists and the number of entries in the instcollist is different from the number of entries in the exprlist.
H43846: The preparation of an INSERT VALUE statement shall fail with an error if the columnlist element does not exists and the number of entries in the exprlist is different from the number of columns in the table or view identified by fullname.

4.1.2 INSERT SELECT

syntaxreq {H43870} {} {} { The SQLite parser shall accept INSERT SELECT statements that conform to the following syntax: } { insert_contents ::= select. } syntaxreq {H43873} {} {} { The preparation of an INSERT SELECT statement shall fail with an error if the columnlist element exists and the number of entries in the instcollist is different from the number of columns in the result set of select. } syntaxreq {H43876} {} {} { The preparation of an INSERT SELECT statement shall fail with an error if the columnlist element does not exists and the number of columns in the result set of the select is different from the number of columns in the table or view identified by fullname. }

4.1.3 INSERT DEFAULT

H43890: The SQLite parser shall accept INSERT DEFAULT statements that conform to the following syntax:
insert_contents ::= DEFAULT VALUES.

4.2 DELETE

H43900: The SQLite parser shall accept DELETE statements that conform to the following syntax:
cmd ::= DELETE FROM fullname where.
where ::= .
where ::= WHERE expr.
H43904: The preparation of a DELETE statement shall fail with an error if the fullname element does not identify a view with an INSTEAD OF DELETE trigger or a table.
H43907: The preparation of a DELETE statement shall fail with an error if the objectname of the fullname element is "sqlite_master" or "sqlite_temp_master" and the database connection is not in writeable_schema mode.
H43911: Name resolution in the where term of a DELETE statement shall be carried out using a name context with an empty result set and a source set holding single source element that is the fullname table.

4.3 UPDATE

H44100: The SQLite parser shall accept UPDATE statements that conform to the following syntax:
cmd ::= update_cmd fullname SET setlist where.
update_cmd ::= UPDATE.
update_cmd ::= UPDATE OR IGNORE.
update_cmd ::= UPDATE OR REPLACE.
update_cmd ::= UPDATE OR ABORT.
update_cmd ::= UPDATE OR FAIL.
update_cmd ::= UPDATE OR ROLLBACK.
setlist ::= setting.
setlist ::= setlist COMMA setting.
setting ::= columnname EQ expr.
H44113: The preparation of an UPDATE statement shall fail with an error if any columnname is not a column in the table identified by fullname and is not one of the special columns named "ROWID", "OID", or "_ROWID_".
H44116: The preparation of an UPDATE statement shall fail with an error if fullname does not identify either a view with an INSTEAD OF UPDATE trigger that covers all columnnames or a table.
H44119: The preparation of an UPDATE statement shall fail with an error if the objectname of the fullname is "sqlite_master" or "sqlite_temp_master" and the database connection is not in writeable schema mode.
H44121: When the form of an UPDATE statement is simply "UPDATE" then the default null- and uniqueness-conflict resolution algorithms shall be used.
H44127: When the form of an UPDATE statement is "UPDATE OR algorithm" then the null- and uniqueness-conflict resolution algorithms shall all change to algorithm.
H44131: Name resolution in the where term of a DELETE statement shall be carried out using a name context with an empty result set and a source set holding single source element that is the fullname table.

4.4 SELECT

H45000: The SQLite parser shall accept SELECT statements that conform to the following syntax:
cmd ::= select.
select ::= query.
select ::= select UNION query.
select ::= select UNION ALL query.
select ::= select EXCEPT query.
select ::= select INTERSECT query.
query ::= SELECT distinct resultset from where groupby having orderby limit.
distinct ::= .
distinct ::= DISTINCT.
groupby ::= .
groupby ::= GROUP BY exprlist.
having ::= .
having ::= HAVING expr.
orderby ::= .
orderby ::= ORDER BY exprlist.
limit ::=.
limit ::= LIMIT expr.
limit ::= LIMIT expr COMMA expr.
limit ::= LIMIT expr OFFSET expr.
resultset ::= result.
resultset ::= resultset COMMA result.
result ::= STAR.
result ::= tablename DOT STAR.
result ::= expr as.
from ::= .
from ::= FROM sourceset.
sourceset ::= source.
sourceset ::= sourceset joinop source.
source ::= fullname as on using.
source ::= LP select RP as on using.
as ::= .
as ::= AS name.
as ::= identifier.
on ::= .
on ::= ON expr.
using ::= .
using ::= USING LP columnlist RP.
joinop ::= COMMA.
joinop ::= JOIN.
joinop ::= JOIN_KW JOIN.
joinop ::= JOIN_KW JOIN_KW JOIN.
joinop ::= JOIN_KW JOIN_KW JOIN_KW JOIN.

A sequence of query terms connected by UNION, UNION ALL, EXCEPT, and/or INTERSECT operators is called a "compound query" and the individual query terms are call "terms of the compound query".

H45003: The preparation of a statement containing a select shall fail with an error if the select contains two terms of the same compound query having a different number of columns in their result sets.
H45006: The preparation of a statement containing a select shall fail with an error if the select contains a compound query that has an ORDER BY, GROUP BY, HAVING, or LIMIT clause on any term of than the right-most.
H45009: The preparation of a statement containing a select shall fail with an error if the select contains a compound query with an ORDER BY or GROUP BY clause with a term that is not either a token-by-token duplicate of the result columns of one of the compound query terms, or the "AS" name of one of the compound query terms, or a compile-time integer between 1 and N where N is the number of columns in each compound query term.
H45012: The preparation of a statement containing a select shall fail with an error if the select contains a join with two or more of the following properties:
  1. The NATURAL keyword in the joinop
  2. An ON clause
  3. A USING clause
H45015: The preparation of a statement containing a select shall fail with an error if the select contains a joinop that uses the keywords RIGHT or FULL.
H45018: The preparation of a statement containing a select shall fail with an error if the select contains a joinop that uses either of the keywords OUTER or LEFT together with either INNER or CROSS.
H45021: The preparation of a statement containing a select shall fail with an error if the select contains a using that names columns that are not found in both the table to the immediate right of the join and in the result set of all tables to the left of the join.
H45024: The preparation of a statement containing a select shall fail with an error if the fullname of a source does not refer to an existing table or view.
H45027: The preparation of a statement containing a limit shall fail with an error if any expr within the limit does not evaluate to a compile-time integer.

4.4.1 Name resolution with SELECT statements

H45103: Name resolution of a top-level SELECT statement shall use an empty name context.
H45106: Name context of a query term shall be constructed by adding a new inner name context layer to the name context of the construct containing the query term.
H45109: Name resolution of the resultset of a query shall use the name context of the query with an empty result set and the source set configured to the from clause of the query.
H45112: Name resolution of all child terms of a query other than resultset child shall use the name context of the query with the result set configured to be the resultset clause of the query and with the source set configured to be the from clause of the query.

5.0 Other Language Elements

5.1 VACUUM

H44200: The SQLite parser shall accept VACUUM statements that conform to the following syntax:
cmd ::= VACUUM.
cmd ::= VACUUM name.

5.2 ANALYZE

H44300: The SQLite parser shall accept ANALYZE statements that conform to the following syntax:
cmd ::= ANALYZE.
cmd ::= ANALYZE fullname.
H44303: The preparation of an ANALYZE statement shall fail with an error if the fullname is included and does not evaluate to either an individual table name or the name of a database.

5.3 REINDEX

H44400: The SQLite parser shall accept REINDEX statements that conform to the following syntax:
cmd ::= REINDEX.
cmd ::= REINDEX fullname.
H44403: The preparation of an ANALYZE statement shall fail with an error if the fullname is included and does not evaluate to either an individual table name or the name of a database or the name of a collating sequence.

5.4 PRAGMA

H46000: The SQLite parser shall accept PRAGMA statements that conform to the following syntax:
cmd ::= PRAGMA fullname EQ DELETE.
cmd ::= PRAGMA fullname EQ ON.
cmd ::= PRAGMA fullname EQ name.
cmd ::= PRAGMA fullname EQ expr.
cmd ::= PRAGMA fullname LP name RP.
cmd ::= PRAGMA fullname LP expr RP.
cmd ::= PRAGMA fullname.

The objectname of the fullname of a PRAGMA is called the PRAGMA verb.

H46003: The evaluation of a PRAGMA statement with an unknown verb shall be a silent no-op.

5.5 ATTACH

The SQLite parser shall accept ATTACH statements that conform to the following syntax:

H44500: cmd ::= ATTACH database_kw expr AS expr. database_kw ::= . database_kw ::= DATABASE.
H44503: The expr terms of an ATTACH statement that are identifiers shall be interpreted as string literals.
H44506: The preparation of an ATTACH statement shall fail with an error if either expr is not a constant expression.
H44509: The preparation of an ATTACH statement shall fail with an error if the second expr evaluates to the name of a database that is already attached to the database connection.

5.6 DETACH

H44600: The SQLite parser shall accept DETACH statements that conform to the following syntax:
cmd ::= DETACH database_kw expr.
H44603: The expr term of an DETACH statement that is an identifier shall be interpreted as string literals.
H44606: The preparation of an DETACH statement shall fail with an error if the expr is not a constant expression.
H44609: The preparation of an DETACH statement shall fail with an error if the expr does not evaluate to the name of an attached database other than "temp" or "main".

5.7 EXPLAIN

H44700: The SQLite parser shall accept the EXPLAIN keyword as a prefix to other valid SQL statements, as shown by the following syntax:
sql_statement ::= EXPLAIN cmd SEMI.

5.8 EXPLAIN QUERY PLAN

H44800: The SQLite parser shall accept EXPLAIN QUERY PLAY as a prefix to other valid SQL statements, as shown by the following syntax:
sql_statement ::= EXPLAIN QUERY PLAN cmd SEMI.

6.0 Common Language Subelements

6.1 Expressions

H47000: The SQLite parser shall accept expressions that conform to the following syntax:
expr ::= BITNOT expr.
expr ::= CASE case_operand case_exprlist case_else END.
expr ::= CAST LP expr AS typetoken RP.
expr ::= EXISTS LP select RP.
expr ::= function_name LP STAR RP.
expr ::= function_name LP distinct exprlist RP.
expr ::= LP expr RP.
expr ::= LP select RP.
expr ::= MINUS expr.
expr ::= NOT expr.
expr ::= PLUS expr.
expr ::= RAISE LP IGNORE RP.
expr ::= RAISE LP ABORT COMMA name RP.
expr ::= RAISE LP FAIL COMMA name RP.
expr ::= RAISE LP ROLLBACK COMMA name RP.
expr ::= VARIABLE.
expr ::= expr AND expr.
expr ::= expr BITAND expr.
expr ::= expr BITOR expr.
expr ::= expr LSHIFT expr.
expr ::= expr RSHIFT expr.
expr ::= expr COLLATE ids.
expr ::= expr CONCAT expr.
expr ::= expr EQ expr.
expr ::= expr NE expr.
expr ::= expr IS NOT NULL.
expr ::= expr IS NULL.
expr ::= expr ISNULL
expr ::= expr NOTNULL.
expr ::= expr LT expr.
expr ::= expr GT expr.
expr ::= expr GE expr.
expr ::= expr LE expr.
expr ::= expr NOT NULL.
expr ::= expr OR expr.
expr ::= expr PLUS expr.
expr ::= expr MINUS expr.
expr ::= expr STAR expr.
expr ::= expr SLASH expr.
expr ::= expr REM expr.
expr ::= expr BETWEEN expr AND expr.
expr ::= expr NOT BETWEEN expr AND expr.
expr ::= expr IN LP exprlist RP.
expr ::= expr IN LP select RP.
expr ::= expr IN fullname.
expr ::= expr NOT IN LP exprlist RP.
expr ::= expr NOT IN LP select RP.
expr ::= expr NOT IN fullname.
expr ::= expr LIKE_KW expr escape.
expr ::= expr MATCH expr escape.
expr ::= expr NOT LIKE_KW expr escape.
expr ::= expr NOT MATCH expr escape.
expr ::= rtvalue.
expr ::= term.
term ::= CTIME_KW.
term ::= INTEGER.
term ::= FLOAT
term ::= BLOB.
term ::= NULL.
term ::= STRING.
exprlist ::= expr.
exprlist ::= exprlist COMMA expr.
case_else ::= ELSE expr.
case_else ::= .
case_exprlist ::= WHEN expr THEN expr.
case_exprlist ::= case_exprlist WHEN expr THEN expr.
case_operand ::= expr.
case_operand ::= .
function_name ::= ID.
escape ::= .
escape ::= ESCAPE expr.
H47003: The unary PLUS, unary MINUS, and BITNOT operators shall have precedence over the COLLATE operator.
H47006: The COLLATE operator shall have precedence over the CONCAT operator.
H47009: The CONCAT operator shall have precedence over the STAR, SLASH, and REM operators.
H47012: The STAR, SLASH, and REM operator shall have equal precedence.
H47015: The STAR, SLASH, and REM operators shall have precedence over the binary PLUS and binary MINUS operators.
H47018: The binary PLUS and binary MINUS operators shall have equal precedence.
H47021: The binary PLUS and binary MINUS operators shall have precedence over the BITAND, BITOR, LSHIFT, and RSHIFT operators.
H47024: The BITAND, BITOR, LSHIFT, and RSHIFT operators shall have equal precendence.
H47027: The BITAND, BITOR, LSHIFT, and RSHIFT operators shall have precedence over the ESCAPE operator.
H47029: The ESCAPE operator shall have precedence over the GT, LE, LT, and GE operators.
H47033: The GT, LE, LT, and GE operators shall have equal precedence.
H47036: The GT, LE, LT, and GE operators shall have precedence over the IS, MATCH, LIKE_KW, BETWEEN, IN, ISNULL, NOTNULL, NE, and EQ operators shall have equal precedence.
H47039: The IS, MATCH, LIKE_KW, BETWEEN, IN, ISNULL, NOTNULL, NE, and EQ operators shall have equal precedence.
H47042: The IS, MATCH, LIKE_KW, BETWEEN, IN, ISNULL, NOTNULL, NE, and EQ operators shall have precedence over the unary NOT operator.
H47045: The unary NOT operator shall have precedence over the AND operator.
H47048: The AND operator shall have precedence over the OR operator.
H47051: Operators of equal precedence shall group from right to left.

6.2 Symbolic Names

H49100: The SQLite parser shall accept names, fullnames, and identifiers that conform to the following syntax:
name ::= ID.
name ::= JOIN_KW.
name ::= STRING.
fullname ::= objectname.
fullname ::= databasename DOT objectname.
objectname ::= name.
databasename ::= name.
columnname ::= name.
identifier ::= ID.
identifier ::= STRING.
H49103: The SQLite parser shall accept rtvalue elements of an expr that conform to the following syntax:
rtvalue ::= databasename DOT tablename DOT columnname.
rtvalue ::= tablename DOT columnname.
rtvalue ::= ID.
rtvalue ::= JOIN_KW.

This page last modified 2008/08/13 22:29:43 UTC