Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 函数中多个值的过滤_Postgresql - Fatal编程技术网

Postgresql 函数中多个值的过滤

Postgresql 函数中多个值的过滤,postgresql,Postgresql,我的问题的非函数版本很简单:我想根据文本变量是否具有某些特定值来筛选值: SELECT routine_name, data_type FROM information_schema.routines WHERE data_type IN ('boolean', 'integer'); 因为我想对我正在过滤的内容做很多变化,所以我想有一个接受要过滤的值的函数。我试图将其转换为函数,如下所示: CREATE FUNCTION get_fns_by_data_type(data_type

我的问题的非函数版本很简单:我想根据文本变量是否具有某些特定值来筛选值:

SELECT routine_name, data_type
  FROM information_schema.routines
   WHERE data_type IN ('boolean', 'integer');
因为我想对我正在过滤的内容做很多变化,所以我想有一个接受要过滤的值的函数。我试图将其转换为函数,如下所示:

CREATE FUNCTION get_fns_by_data_type(data_types text[])
  RETURNS TABLE(routine_name text, data_type text) AS $$
BEGIN
  RETURN QUERY SELECT routine_name, data_type
    FROM information_schema.routines
    WHERE data_type IN (array_to_string($1, ','));
END;
$$ LANGUAGE plpgsql;
当我称之为:

SELECT * FROM get_fns_by_data_type(ARRAY['boolean', 'integer'])
我没有结果

我怀疑我应该以某种方式引用这些值,但我不确定最好的方法是什么,也不确定如何调试这个问题


如何在我的
WHERE
子句中使用数组?

array\u to\u string
返回单个字符串,而不是字符串列表,因此在函数中实际运行的是:

where data_type IN ('boolean, integer') 
(这显然不是你想要的)

首先不需要转换数组。你可以直接使用它

where data_type = any ($1)