2016-05-19 34 views
2

語法錯誤創建指數繼Postgres trgm docs的指示,我能夠創造同時使用GINGiST指標:Postgres的:使用PRGM GIN

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 

回答

2

desc是保留字。用雙引號括起來,它會起作用:

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