【问题标题】:Converting psql text column to tsvector将 psql 文本列转换为 tsvector
【发布时间】:2022-01-20 01:14:45
【问题描述】:

我正在尝试使用 Rails 迁移将文本列转换为 tsvector:

change_column :people, :title, "tsvector USING title::tsvector"

它被特殊字符所吸引,例如:

ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR:  syntax error in tsvector: "Project Manager: Software"

由于某种原因,如果我更新列,比如在末尾添加一个空格,然后重新运行它们迁移,它就可以工作。

任何想法为什么?到目前为止,它的字段包含::, &, í

【问题讨论】:

    标签: postgresql psql


    【解决方案1】:

    to_tsvector() 用于将纯文本转换为 tsvector。

    ::tsvector 用于断言给定文本已经是 tsvector 的有效表示,而您的则不是。

    【讨论】:

    • 谢谢!这就是我需要的:change_column :people, :title, "tsvector USING to_tsvector(title)"
    猜你喜欢
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多