2017-10-18 65 views
0

我有PostgreSQL的ltree扩展9.6.5语法错误在查询9.6.5

我有一个名为具有以下DDL类别表(我简化了一点)一个问题:

CREATE TABLE dictionary.category 
(
    id serial not null constraint category_pkey primary key, 
    name text not null, 
    parent_id integer constraint category_parent_id_fkey references dictionary.category 
); 

创作ltree延长后:

CREATE EXTENSION ltree; 

我试图做一些查询例如:

SELECT id, text2ltree(name) FROM dictionary.category; 

SELECT id, name::ltree FROM dictionary.category; 

或逃避列名

SELECT id, text2ltree("name") FROM dictionary.category; 

,这让我:

ERROR: syntax error at position 12 

所有的时间

但是当我尝试:

SELECT id, text2ltree('a.b.v') FROM dictionary.category; 

SELECT id, text2ltree(id::text) FROM dictionary.category 

它给了我正确的结果。

我想这与名称是保留关键字有关。但为什么逃避不起作用?此外,我特此重命名一个列像abcd它无论如何给我语法错误。

谢谢大家提前!

回答

0

回答我自己的问题。看起来这些错误消息与查询本身无关。它与ltree路径中包含的文本有关。看来,l树路径只允许alfanumeric字符,只不过是。

SELECT id, text2ltree(regexp_replace(name, '[^[:alpha:]]', '', 'g')) FROM dictionary.category; 

返回正确的结果。

无论如何,错误信息是非常误导。