postgresql - postgres:不能在名为“文本”的列上使用 to_tsvector
问题描述
我正在使用 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
orconcat_ws
代替 concat 运算符||
。
例如:
update ccnc set fulltext = concat_ws('. ', title, description, text)
推荐阅读
- mysql - 如何在 MySQL 8.0.11 中重置 root 密码?
- javascript - 当 10 个字符全尺寸片假名时换行
- php - 在mysql中转换日期
- java - 为日志方法编写模拟测试用例
- ruby - 如何将模块命名空间添加到 ruby 类/模块?
- php - 调用 Flysystem,为什么会出现 PHP 致命错误:找不到 Class 'League\Flysystem\Adapter\Local'?
- javascript - 字体真棒图标不适用于css不透明度
- python - python pandas dataframe groupby 将同一组放在一起
- image - 如何在 Python 中使用 XBM 图像数据而不引用外部文件
- ios - arc4random_uniform 的 Swift 结果并不总是显示在标签中