【发布时间】:2018-07-17 02:51:59
【问题描述】:
我有以下观点:
CREATE VIEW public.profiles_search AS
SELECT
profiles.id,
profiles.bio,
profiles.title,
(
setweight(to_tsvector(profiles.search_language::regconfig, profiles.title::text), 'B'::"char") ||
setweight(to_tsvector(profiles.search_language::regconfig, profiles.bio), 'A'::"char") ||
setweight(to_tsvector(profiles.search_language::regconfig, profiles.category::text), 'B'::"char") ||
setweight(to_tsvector(profiles.search_language::regconfig, array_to_string(profiles.tags, ',', '*')), 'C'::"char")
) AS document
FROM profiles
GROUP BY profiles.id;
但是,如果profiles.tags 为空,则document 为空,即使其余字段(标题、简历和类别)包含数据。
是否有某种方法可以使该字段成为可选字段,以使其具有空数据不会导致空文档?
【问题讨论】:
-
profiles.tags 在这些情况下是否为空?如果你使用
coalesce(profiles.tags, ARRAY[]::text[])而不是profiles.tags(假设它是一个文本数组),默认为一个空数组而不是null,它会工作吗?
标签: postgresql full-text-search sql-view postgres-9.6