FirebirdSQL logo

Error Conditions

Processing of every SQL statement either completes successfully or fails due to a specific error condition.Error handling can be done both client-side in the application, or server-side using PSQL.

Basic Elements: Statements, Clauses, Keywords

The primary construct in SQL is the statement.A statement defines what the database management system should do with a particular data or metadata object.More complex statements contain simpler constructs — clauses and options.

Clauses

A clause defines a certain type of directive in a statement.For instance, the WHERE clause in a SELECT statement and in other data manipulation statements (e.g. UPDATE, DELETE) specifies criteria for searching one or more tables for the rows that are to be selected, updated or deleted.The ORDER BY clause specifies how the output data — result set — should be sorted.

Options

Options, being the simplest constructs, are specified in association with specific keywords to provide qualification for clause elements.Where alternative options are available, it is usual for one of them to be the default, used if nothing is specified for that option.For instance, the SELECT statement will return all rows that match the search criteria unless the DISTINCT option restricts the output to non-duplicated rows.

Keywords

All words that are included in the SQL lexicon are keywords.Some keywords are reserved, meaning their usage as identifiers for database objects, parameter names or variables is prohibited in some or all contexts.Non-reserved keywords can be used as identifiers, although this is not recommended.From time to time, non-reserved keywords may become reserved, or new (reserved or non-reserved) keywords may be added when new language feature are introduced.Although unlikely, reserved words may also change to non-reserved keywords, or keywords may be removed entirely, for example when parser rules change.

For example, the following statement will be executed without errors because, although ABS is a keyword, it is not a reserved word.

CREATE TABLE T (ABS INT NOT NULL);

On the contrary, the following statement will return an error because ADD is both a keyword and a reserved word.

CREATE TABLE T (ADD INT NOT NULL);

Refer to the list of reserved words and keywords in the chapter Reserved Words and Keywords.

Identifiers

All database objects have names, often called identifiers.The maximum identifier length is 63 characters character set UTF8 (252 bytes).

Note

It is possible to restrict the actual maximum identifier length through configuration.Consult theFirebird 4.0 Release Notesfor details.In this language reference we assume the default configuration of 63 characters (252 bytes).

Two types of names are valid as identifiers: regular identifiers, similar to variable names in regular programming languages, and delimited identifiers that are specific to SQL.To be valid, each type of identifier must conform to a set of rules, as follows:

Rules for Regular Identifiers

  • Length cannot exceed 63 characters

  • The name must start with an unaccented, 7-bit ASCII alphabetic character.It may be followed by other 7-bit ASCII letters, digits, underscores or dollar signs.No other characters, including spaces, are valid.The name is case-insensitive, meaning it can be declared and used in either upper or lower case.Thus, from the system’s point of view, the following names are the same:

    fullname
    FULLNAME
    FuLlNaMe
    FullName
  • Regular identifiers are stored in uppercase

Regular name syntax
<name> ::=
  <letter> | <name><letter> | <name><digit> | <name>_ | <name>$

<letter> ::= <upper letter> | <lower letter>

<upper letter> ::= A | B | C | D | E | F | G | H | I | J | K | L | M |
                   N | O | P | Q | R | S | T | U | V | W | X | Y | Z

<lower letter> ::= a | b | c | d | e | f | g | h | i | j | k | l | m |
                   n | o | p | q | r | s | t | u | v | w | x | y | z

<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9