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

问题描述 投票:1回答:1

这是我目前的代码:

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

python django postgresql datetime
1个回答
0
投票

我被告知PG FTS尚未处理日期或时间。

© www.soinside.com 2019 - 2024. All rights reserved.