这是我当前的代码:
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/