Postgres:使用prgm GIN创建索引的语法错误

时间:2016-05-19 22:12:21

标签: postgresql indexing

按照Postgres trgm docs的说明,我可以使用GINGiST创建索引:

home_accounting_dev=# \d+ test_trgm
                     Table "public.test_trgm"
 Column | Type | Modifiers | Storage  | Stats target | Description 
--------+------+-----------+----------+--------------+-------------
 t      | text |           | extended |              | 
Indexes:
    "trgm_idx" gist (t gist_trgm_ops)
    "trgm_idx_2" gin (t gin_trgm_ops)
Has OIDs: no

...但我似乎无法在现有的表格“支出”,“desc”栏目中这样做。

home_accounting_dev=# \d+ expenditures
                                                          Table "public.expenditures"
   Column    |            Type             |                         Modifiers                         | Storage  | Stats target | Description 
-------------+-----------------------------+-----------------------------------------------------------+----------+--------------+-------------
 id          | integer                     | not null default nextval('expenditures_id_seq'::regclass) | plain    |              | 
 desc        | text                        |                                                           | extended |              | 
 amount      | character varying(255)      |                                                           | extended |              | 
 inserted_at | timestamp without time zone | not null                                                  | plain    |              | 
 updated_at  | timestamp without time zone | not null                                                  | plain    |              | 
 expent_at   | date                        |                                                           | plain    |              | 
Indexes:
    "expenditures_pkey" PRIMARY KEY, btree (id)
Referenced by:
    TABLE "expenditures_taggings" CONSTRAINT "expenditures_taggings_assoc_id_fkey" FOREIGN KEY (assoc_id) REFERENCES expenditures(id)
Has OIDs: no

该列与test_trgm表中的示例“t”列完全相同,但在尝试创建索引时会抛出语法错误:

home_accounting_dev=# CREATE INDEX asdf_qwer ON expenditures USING gin (desc gin_trgm_ops);
ERROR:  syntax error at or near "desc"
LINE 1: CREATE INDEX asdf_qwer ON expenditures USING gin (desc gin_t...

如果我对列名称进行了错误输入,则会失败:

home_accounting_dev=# CREATE INDEX asdf_qwer ON expenditures USING gin (dec gin_trgm_ops);
ERROR:  column "dec" does not exist

1 个答案:

答案 0 :(得分:3)

desc是保留字。用双引号括起来它会起作用:

CREATE INDEX asdf_qwer ON expenditures USING gin ("desc" gin_trgm_ops);