Using keywords as table names
The database server issues an error in contexts where the unqualified identifier of a table object is also a valid keyword of SQL. You can disambiguate the table name by qualifying it with the authorization identifier of the owner of the table.
Examples that follow illustrate owner-name qualifiers as workarounds
when the keyword STATISTICS
, OUTER
,
or FROM
has been declared as a table name or synonym.
(These examples also apply if any of those keywords is the identifier
of a view.)
UPDATE statistics SET mycol = 10; -- fails
UPDATE josh.statistics SET mycol = 10;
SELECT mycol FROM outer; -- fails
SELECT mycol FROM josh.outer;
The following DELETE statement, whose target table was created with from as its identifier, returns a syntax error:
DELETE from; -- fails
Because FROM
is also an optional keyword that
immediately precedes the name of the table whose records are to be
destroyed, the database server expects a table name after FROM
.
Finding none, it issues an exception.
The following example, in contrast, deletes all the rows from what it correctly recognizes as the from table, because that table name is qualified by the name of its owner:
DELETE zelaine.from;
If the DELIMIDENT environment variable is set on the database
server, an alternative workaround is to use double quotation marks
( "
) as delimiters.
DELETE "from";
This avoids the exception by indicating that from is an SQL identifier, rather than a string literal or an SQL keyword.
Despite the availability of these workarounds, your code will be easier for humans to read and to maintain if you avoid declaring SQL keywords as the identifiers of tables, views, or other database objects.