python - Django 与 Postgresql 全文搜索日期和时间输入类型错误

标签 python django postgresql datetime

这是我当前的代码:

class EntryManager(models.Manager):
   def with_documents(self):
       vector = SearchVector('title', weight='A') + \
                SearchVector('slug', weight='B') + \
                SearchVector('content', weight='C') + \
                SearchVector('category', weight='D') + \
                SearchVector(StringAgg('tags__slug', delimiter=' ')) + \
                SearchVector('chron_date')
       if SearchVector('chron_date') == "":
           SearchVector('chron_date') == None
       if SearchVector('clock') == "":
           SearchVector('clock') == None
       return self.get_queryset().annotate(document=vector)

这是我的错误:

invalid input syntax for type date: ""
LINE 1: ...| to_tsvector(COALESCE("ktab_entry"."chron_date", ''))) AS "...

我首先在我的代码的先前版本中遇到此错误,当时我遵循了此处发布的建议:http://kb.tableau.com/articles/issue/error-invalid-input-syntax-for-type-date-error-while-executing-the-query通过在末尾添加两个 if 子句,但这没有用。我在 SO 上看到了这个答案:Error on using copy Command in Postgres (ERROR: invalid input syntax for type date: "")但我的引号中没有空格。这个问题关于 SO invalid input syntax for type date: "" in django, postgresql?没有答案。 FWIW,chron_date 和 clock 字段实际上都有一个值:分别为 2017-11-02 和 14:41:00。我已经尝试更改 datestyle() 无效。我还在模型上添加了 null=True 但仍然出现相同的错误。

Ubuntu 16.04 上的 Django 1.11.5、Postgresql 9.4、Python 3.6

最佳答案

我被告知 PG FTS 还不能处理日期或时间。

关于python - Django 与 Postgresql 全文搜索日期和时间输入类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47106322/

相关文章:

django - 我如何将字段链接到 Django 模型中的多值字段

django csrf RequestContext

python - 如何使用 Python 在 Selenium 中测试 Alert/Popup

python - 替换 pandas 数据框中的多个字符

Django、ReportLab PDF 生成附加在电子邮件中

postgresql - 在 Postgresql 中修改触发器

postgresql - 为什么 Flask 应用程序需要 models.py?

python - key 在 django 中表单的 clean 方法中的已清理数据中不可用

python - 如何用抽象模型定义外键关系?

postgresql - SQL、Postgres OID 是动态的还是静态的