我需要将一个数组传递给 AWS Redshift 上定义的准备好的语句来过滤我的查询。由于 Redshift 不支持此功能,因此我尝试使用 Python UDF 找到解决方法。就像是:
-- a function to split a comma separated list of values (string is already validated)
CREATE FUNCTION split_str_to_ints (string char) RETURNS int[] IMMUTABLE as $$
def split_stoi(string):
ints = [int(item) for item in string.split(',')]
return ints
$$ LANGUAGE plpythonu;
-- a prepared statement to return orders filtered by company id
PREPARE get_orders (char) as
SELECT order.id
order.company_id,
COUNT(order.id) AS order_count
FROM order
INNER JOIN company ON (order.company_id = company.company_id)
WHERE company.company_id IN (split_str_to_ints($1))
GROUP BY order.id, order.company_id
ORDER BY order_count DESC;
EXECUTE get_orders('1,2,3,4')
但是,当我想定义该函数时,出现错误,指出整数数组不是受支持的 plpythonu UDF 返回类型。
有没有其他方法可以将整数(或字符)列表传递给 Redshift 上的预准备语句?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)