问题描述:
遇到关键字无法使用作为表名或列名
分析与解决方法:
一般出现无法使用作为表名或列名的关键字,我们都采取将表或列名用双引号将其引用。使用双引号(标识符)时,表名和列名区分大小写,这意味着被标识符包起来的对象,写到数据库的原信息就是区分大小写的。
例子如下:
不使用标识符“”时候: TEST=# create table tb2(create int); ERROR: syntax error at or near "create" LINE 1: create table tb2(create int); ^ TEST=# create table tb3(col int); CREATE TABLE TEST=# \d+ tb3; Table "PUBLIC.TB3" Column | Type | Modifiers | Storage | Stats target | Description --------+---------+-----------+---------+--------------+------------- COL | INTEGER | | plain | | 使用标识符时候: TEST=# create table "tb4"("col" int); CREATE TABLE TEST=# \d+ tb4; Did not find any relation named "tb4". TEST=# \d+ "tb4"; Table "PUBLIC.tb4" Column | Type | Modifiers | Storage | Stats target | Description --------+---------+-----------+---------+--------------+------------- col | INTEGER | | plain | | TEST=# create table tb5("create" int); CREATE TABLE TEST=# \d+ tb5; Table "PUBLIC.TB5" Column | Type | Modifiers | Storage | Stats target | Description --------+---------+-----------+---------+--------------+------------- create | INTEGER | | plain | |