![](/img/trans.png)
[英]Why use ::tsvector when you have to_tsvector in Postgres?
[英]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”之類的列名,但避免錯誤的一種方法是使用concat
或concat_ws
而不是 concat 運算符||
.
例如:
update ccnc set fulltext = concat_ws('. ', title, description, text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.