Django的PostgreSQL的全文搜索时间输入类型错误
问题描述:
这里是我当前的代码:Django的PostgreSQL的全文搜索时间输入类型错误
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,但仍然出现相同的错误。
的Django 1.11.5和PostgreSQL 9.4,Python的3.6在Ubuntu 16.04
答
我告诉PG FTS还没有处理的日期或时间。