postgresql:select语句中iterable的数据类型

postgresql:select语句中iterable的数据类型,sql,arrays,Sql,Arrays,我正在尝试创建一个可在select语句中使用的iterable变量。如果我硬编码变量,我的代码块工作正常: DO $$ DECLARE num integer; BEGIN num := (select count(*) from event where event_status in ('pending', 'failed')); raise notice 'count here: %', num; END; $$ 但是,如果我试图从iterable中创建一个名为status的变

我正在尝试创建一个可在select语句中使用的iterable变量。如果我硬编码变量,我的代码块工作正常:

DO
$$
DECLARE
  num integer;
BEGIN
  num := (select count(*) from event where event_status in ('pending', 'failed'));
  raise notice 'count here: %', num;
END;
$$
但是,如果我试图从iterable中创建一个名为
status
的变量,我会得到一个错误,即“syntax error at or or near”array:


我是否使用了错误的数据类型?如何才能让它工作?请注意,我使用的是PostgreSQL。

有关如何创建与MySQL的
FIND_IN_SET()函数等价的PG的信息,请参阅。
然后使用逗号分隔的字符串
status:=“挂起,失败”可以是try
状态文本[]::=“{”挂起“,”失败“}”
。但不确定语法。@Hitobat收到错误:
语法错误位于或接近“状态”
DO
$$
DECLARE
  statueses array := ('pending', 'failed');
  num integer;
BEGIN
  num := (select count(*) from event where event_status in statuses);
  raise notice 'count here: %', num;
END;
$$