小编jon*_*nes的帖子

如何在Postgres中检查数组是否为空

我有一个Postgres功能:

CREATE OR REPLACE FUNCTION get_stats(
    _start_date timestamp with time zone,
    _stop_date timestamp with time zone,
    id_clients integer[],
    OUT date timestamp with time zone,
    OUT profit,
    OUT cost
)
RETURNS SETOF record
LANGUAGE plpgsql
AS $$
DECLARE
    query varchar := '';
BEGIN
... -- lot of code
IF id_clients IS NOT NULL THEN
    query := query||' AND id = ANY ('||quote_nullable(id_clients)||')';
END IF;
... -- other code
END;
$$;
Run Code Online (Sandbox Code Playgroud)

所以如果我运行这样的查询:

SELECT * FROM get_stats('2014-07-01 00:00:00Etc/GMT-3'
                      , '2014-08-06 23:59:59Etc/GMT-3', '{}');
Run Code Online (Sandbox Code Playgroud)

生成的查询具有以下条件: …

sql arrays postgresql null stored-procedures

31
推荐指数
2
解决办法
4万
查看次数

标签 统计

arrays ×1

null ×1

postgresql ×1

sql ×1

stored-procedures ×1