Amazon redshift 使用LISTAGG时出现红移错误:必须在至少一个用户创建的表上应用一个或多个已用函数

Amazon redshift 使用LISTAGG时出现红移错误:必须在至少一个用户创建的表上应用一个或多个已用函数,amazon-redshift,Amazon Redshift,我在红移中使用listag(),where条件是对作为主键的bigint列执行null检查 查询: 从帐户id为空的票据中选择listagg(显示id) 它抛出了一个错误: 必须在至少一个用户创建的表上应用一个或多个已用函数。仅用户表函数的示例有LISTAGG、MEDIAN、PERCENTILE_CONT等 该栏的详细信息如下: 列|类型|排序规则|可为空 帐户id|bigint|非空 目标是不获取特定帐户id的数据 有什么替代方法来解决这个问题吗?问题是在红移中,listagg不适用于带有始终

我在红移中使用listag(),where条件是对作为主键的bigint列执行null检查

查询:

从帐户id为空的票据中选择listagg(显示id)

它抛出了一个错误:

必须在至少一个用户创建的表上应用一个或多个已用函数。仅用户表函数的示例有LISTAGG、MEDIAN、PERCENTILE_CONT等

该栏的详细信息如下:

列|类型|排序规则|可为空

帐户id|bigint|非空

目标是不获取特定帐户id的数据
有什么替代方法来解决这个问题吗?

问题是在红移
中,listagg
不适用于带有始终为false的“where”子句的查询。有疑问的是,account_id从不为null,因为表定义不允许它

不幸的是,红移错误文本并没有使这一点变得明显,但AWS论坛上有一个相关的线程:

您可以通过在Redshift上运行以下示例来测试这一点

-- Create a temp table with not null account_id

create table #ticket (display_id int, account_id bigint not null);
insert into #ticket values (1,1), (1,2), (2,4), (3, 5), (3,1);

-- This query like the example in the question fails because the where clause always evaluates to false
select listagg(display_id) from #ticket where account_id is null;

-- This fails with the same error
select listagg(display_id) from #ticket where false;

-- But both these example succeed
select listagg(display_id) from #ticket;
select listagg(display_id) from #ticket where true;
下面是同一个示例,但这次该表允许account_id为空值,并且查询成功

-- Create another temp table that allows null account_id

create table #ticket2 (display_id int, account_id bigint);
insert into #ticket2 values (1,1), (1,2), (2,null), (3, null), (3,1);

-- This query like the example in the question now suceeds
select listagg(display_id) from #ticket2 where account_id is null;

-- These also succeed
select listagg(display_id) from #ticket2;
select listagg(display_id) from #ticket2 where true;

-- This one fails with the same error
select listagg(display_id) from #ticket2 where false;

如果可能的话,请分享您的sql和一些示例数据(编辑您的问题),您是否可以尝试从帐户id为空的票证中选择listagg(display_id::text);sql是:从帐户id为空的票证中选择listagg(显示id);并从帐户id为空的票证中选择listagg(display_id::text);它也不起作用