我尝试定义一个索引视图以在其上创建全文搜索索引。视图本身已正确创建:
CREATE OR ALTER VIEW dbo.my_view WITH SCHEMABINDING AS
SELECT p.id as protector_id,
p.name as protector_name,
string_agg(cast(c.name as nvarchar(max)), ', ') as crops_names,
count_big(*) as count_big
FROM dbo.protectors p
INNER JOIN dbo.protectors_crops pc on p.id = pc.protector_id
INNER JOIN dbo.crops c on pc.crop_id = c.id
GROUP BY p.id, p.name
但是当我尝试创建索引时:
CREATE UNIQUE CLUSTERED INDEX my_view_index ON dbo.my_view (protector_id)
我收到一个错误:
[S0001][10125] Cannot create index on view "dbo.my_view" because it uses aggregate "STRING_AGG". Consider eliminating the aggregate, not indexing the view, or using alternate aggregates. For example, for AVG substitute SUM and COUNT_BIG, or for COUNT, substitute COUNT_BIG.
文档没有说明任何关于 STRING_AGG 的内容,我也找不到任何解决方案来替换它。