Links

C. SQL 關鍵字

Table C.1 列出了在 SQL 標準和 PostgreSQL 15.2 中作為關鍵字的所有標記。相關說明提供於第 4.1.1 節中。 (由於篇幅原因,僅收錄了 SQL 標準的最新兩個版本,以及用於歷史對比的 SQL-92,與其他中間標準版本差異較小。)
SQL 區分保留(reserved)關鍵字和非保留(non-reserved)關鍵字。 根據標準,只有保留關鍵字才是真正的關鍵字; 他們永遠不允許作為標識字串。 非保留關鍵字則只在特定的用法中有特殊的含義,而在其他用法中可以作為標識字串使用。 大多數非保留關鍵字實際上是 SQL 指定的內建資料表和函數的名稱。非保留關鍵字的概念本質上只是為了聲明在某些用法中增加了一些預先定義的含義。
在 PostgreSQL 解析器中,情況有點複雜。 有幾種不同類別的標記,從永遠不能用作標識字串的標記,到在解析器中絕對沒有特殊地位,但被視為普通標識字串的標記都有。 (後者通常是 SQL 指定的函數。)即使保留關鍵字在 PostgreSQL 中也沒有完全保留,而是可以用作欄位標籤(例如 SELECT 55 AS CHECK 是可以的,儘管 CHECK 是保留關鍵字) .
Table C.1 的 PostgreSQL 欄位中,我們將解析器明確知道但允許作為欄位名稱或資料表名稱的那些關鍵字分類為“non-reserved”。 一些非保留的關鍵字不能用作函數或資料型別名稱,並相應地進行標記。 (這些詞大多表示具有特殊語法的內建函數或資料型別。函數或型別仍然可用,但使用者不能重新定義。)標記為“reserved”的是那些不允許作為欄位或資料表名稱的標記。 允許一些保留關鍵字作為函數或資料型別的名稱; 這也顯示在表格中。 如果沒有這樣標記,保留關鍵字僅允許作為欄位標籤。 此欄中的空白項目表示該關鍵字被 PostgreSQL 視為普通標識字串。
此外,雖然大多數關鍵字可以直接用作欄位標籤而毋須在它們之前使用 AS(如第 7.3.2 節所述),但有一些關鍵詞需要前導 AS 以避免歧義。 在下表中這些關鍵字會標記為“requires AS”。
一般來說,如果使用任何列出的關鍵字作為標識字的命令出現解析錯誤的時候,您應該嘗試將標識字以雙引號括住,再查看問題是否消失。
在研究 Table C.1 之前,重要的是要了解,在 PostgreSQL 中沒有保留關鍵字並不意味著沒有實作與該關鍵字相關的功能。 同樣地,關鍵字的存在也不表示其功能的存在。

Table C.1. SQL Key Words

Key Word
PostgreSQL
SQL:2016
SQL:2011
SQL-92
A
non-reserved
non-reserved
ABORT
non-reserved
ABS
reserved
reserved
ABSENT
reserved
non-reserved
ABSOLUTE
non-reserved
non-reserved
non-reserved
reserved
ACCESS
non-reserved
ACCORDING
non-reserved
non-reserved
ACOS
reserved
ACTION
non-reserved
non-reserved
non-reserved
reserved
ADA
non-reserved
non-reserved
non-reserved
ADD
non-reserved
non-reserved
non-reserved
reserved
ADMIN
non-reserved
non-reserved
non-reserved
AFTER
non-reserved
non-reserved
non-reserved
AGGREGATE
non-reserved
ALL
reserved
reserved
reserved
reserved
ALLOCATE
reserved
reserved
reserved
ALSO
non-reserved
ALTER
non-reserved
reserved
reserved
reserved
ALWAYS
non-reserved
non-reserved
non-reserved
ANALYSE
reserved
ANALYZE
reserved
AND
reserved
reserved
reserved
reserved
ANY
reserved
reserved
reserved
reserved
ARE
reserved
reserved
reserved
ARRAY
reserved, requires AS
reserved
reserved
ARRAY_AGG
reserved
reserved
ARRAY_​MAX_​CARDINALITY
reserved
reserved
AS
reserved, requires AS
reserved
reserved
reserved
ASC
reserved
non-reserved
non-reserved
reserved
ASENSITIVE
non-reserved
reserved
reserved
ASIN
reserved
ASSERTION
non-reserved
non-reserved
non-reserved
reserved
ASSIGNMENT
non-reserved
non-reserved
non-reserved
ASYMMETRIC
reserved
reserved
reserved
AT
non-reserved
reserved
reserved
reserved
ATAN
reserved
ATOMIC
non-reserved
reserved
reserved
ATTACH
non-reserved
ATTRIBUTE
non-reserved
non-reserved
non-reserved
ATTRIBUTES
non-reserved
non-reserved
AUTHORIZATION
reserved (can be function or type)
reserved
reserved
reserved
AVG
reserved
reserved
reserved
BACKWARD
non-reserved
BASE64
non-reserved
non-reserved
BEFORE
non-reserved
non-reserved
non-reserved
BEGIN
non-reserved
reserved
reserved
reserved
BEGIN_FRAME
reserved
reserved
BEGIN_PARTITION
reserved
reserved
BERNOULLI
non-reserved
non-reserved
BETWEEN
non-reserved (cannot be function or type)
reserved
reserved
reserved
BIGINT
non-reserved (cannot be function or type)
reserved
reserved
BINARY
reserved (can be function or type)
reserved
reserved
BIT
non-reserved (cannot be function or type)
reserved
BIT_LENGTH
reserved
BLOB
reserved
reserved
BLOCKED
non-reserved
non-reserved
BOM
non-reserved
non-reserved
BOOLEAN
non-reserved (cannot be function or type)
reserved
reserved
BOTH
reserved
reserved
reserved
reserved
BREADTH
non-reserved
non-reserved
non-reserved
BY
non-reserved
reserved
reserved
reserved
C
non-reserved
non-reserved
non-reserved
CACHE
non-reserved
CALL
non-reserved
reserved
reserved
CALLED
non-reserved
reserved
reserved
CARDINALITY
reserved
reserved
CASCADE
non-reserved
non-reserved
non-reserved
reserved
CASCADED
non-reserved
reserved
reserved
reserved
CASE
reserved
reserved
reserved
reserved
CAST
reserved
reserved
reserved
reserved
CATALOG
non-reserved
non-reserved
non-reserved
reserved
CATALOG_NAME
non-reserved
non-reserved
non-reserved
CEIL
reserved
reserved
CEILING
reserved
reserved
CHAIN
non-reserved
non-reserved
non-reserved
CHAINING
non-reserved
CHAR
non-reserved (cannot be function or type), requires AS
reserved
reserved
reserved
CHARACTER
non-reserved (cannot be function or type), requires AS
reserved
reserved
reserved
CHARACTERISTICS
non-reserved
non-reserved
non-reserved
CHARACTERS
non-reserved
non-reserved
CHARACTER_LENGTH
reserved
reserved
reserved
CHARACTER_​SET_​CATALOG
non-reserved
non-reserved
non-reserved
CHARACTER_SET_NAME
non-reserved
non-reserved
non-reserved
CHARACTER_SET_SCHEMA
non-reserved
non-reserved
non-reserved
CHAR_LENGTH
reserved
reserved
reserved
CHECK
reserved
reserved
reserved
reserved
CHECKPOINT
non-reserved
CLASS
non-reserved
CLASSIFIER
reserved
CLASS_ORIGIN
non-reserved
non-reserved
non-reserved
CLOB
reserved
reserved
CLOSE
non-reserved
reserved
reserved
reserved
CLUSTER
non-reserved
COALESCE
non-reserved (cannot be function or type)
reserved
reserved
reserved
COBOL
non-reserved
non-reserved
non-reserved
COLLATE
reserved
reserved
reserved
reserved
COLLATION
reserved (can be function or type)
non-reserved
non-reserved
reserved
COLLATION_CATALOG
non-reserved
non-reserved
non-reserved
COLLATION_NAME
non-reserved
non-reserved
non-reserved
COLLATION_SCHEMA
non-reserved
non-reserved
non-reserved
COLLECT
reserved
reserved
COLUMN
reserved
reserved
reserved
reserved
COLUMNS
non-reserved
non-reserved
non-reserved
COLUMN_NAME
non-reserved
non-reserved
non-reserved
COMMAND_FUNCTION
non-reserved
non-reserved
non-reserved
COMMAND_​FUNCTION_​CODE
non-reserved
non-reserved
COMMENT
non-reserved
COMMENTS
non-reserved
COMMIT
non-reserved
reserved
reserved
reserved
COMMITTED
non-reserved
non-reserved
non-reserved
non-reserved
COMPRESSION
non-reserved
CONCURRENTLY
reserved (can be function or type)
CONDITION
reserved
reserved
CONDITIONAL
non-reserved
CONDITION_NUMBER
non-reserved
non-reserved
non-reserved
CONFIGURATION
non-reserved
CONFLICT
non-reserved
CONNECT
reserved
reserved
reserved
CONNECTION
non-reserved
non-reserved
non-reserved
reserved
CONNECTION_NAME
non-reserved
non-reserved
non-reserved
CONSTRAINT
reserved
reserved
reserved
reserved
CONSTRAINTS
non-reserved
non-reserved
non-reserved
reserved
CONSTRAINT_CATALOG
non-reserved
non-reserved
non-reserved
CONSTRAINT_NAME
non-reserved
non-reserved
non-reserved
CONSTRAINT_SCHEMA
non-reserved
non-reserved
non-reserved
CONSTRUCTOR
non-reserved
non-reserved
CONTAINS
reserved
reserved
CONTENT
non-reserved
non-reserved
non-reserved
CONTINUE
non-reserved
non-reserved
non-reserved
reserved
CONTROL
non-reserved
non-reserved
CONVERSION
non-reserved
CONVERT
reserved
reserved
reserved
COPY
non-reserved
reserved
CORR
reserved
reserved
CORRESPONDING
reserved
reserved
reserved
COS
reserved
COSH
reserved
COST
non-reserved
COUNT
reserved
reserved
reserved
COVAR_POP
reserved
reserved
COVAR_SAMP
reserved
reserved
CREATE
reserved, requires AS
reserved
reserved
reserved
CROSS
reserved (can be function or type)