簡體   English   中英

postgres:不能在名為“文本”的列上使用 to_tsvector

[英]postgres: Cannot use to_tsvector on a column named 'text'

我正在使用 postgres 11.5 並嘗試執行以下操作:

update ccnc set fulltext_tokens = to_tsvector(title || '. ' || description || '. ' || text ) where fulltext_tokens is NULL;

這導致

ERROR:  column " text" does not exist
LINE 1: ...o_tsvector(title || '. ' || description || '. ' || text ) wh...
                                                             ^
HINT:  Perhaps you meant to reference the column "ccnc.text".

但是,使用 ccnc.text 也沒有幫助:

felix=# update ccnc set fulltext_tokens = to_tsvector(title || '. ' || description || '. ' || ccnc.text) where fulltext_tokens is NULL;
ERROR:  missing FROM-clause entry for table " ccnc"
LINE 1: ...o_tsvector(title || '. ' || description || '. ' || ccnc.text...

...相應的列也沒有什么奇怪的(沒有尾隨空格等):

felix=# \d+ ccnc
                                                               Table "public.ccnc"
     Column      |            Type             | Collation | Nullable |             Default              | Storage  | Stats target | Description
-----------------+-----------------------------+-----------+----------+----------------------------------+----------+--------------+-------------
 id              | integer                     |           | not null | nextval('ccnc_id_seq'::regclass) | plain    |              |
 description     | text                        |           |          | ''::text                         | extended |              |
 text            | text                        |           |          |                                  | extended |              |
 title           | text                        |           |          |                                  | extended |              |

編輯:引用也無濟於事,例如:

update ccnc set fulltext =  title || '. ' || description || '. ' || "text";
ERROR:  syntax error at or near ""text""
LINE 1: ... fulltext =  title || '. ' || description || '. ' || "text";

對於如何創建名為 fulltext_tokens 的新列,我將不勝感激。 先感謝您:-)

盡管 Richard 提出了非常有價值的評論,即首先不使用諸如“text”之類的列名,但避免錯誤的一種方法是使用concatconcat_ws而不是 concat 運算符|| .

例如:

update ccnc set fulltext = concat_ws('. ', title, description, text)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM