【问题标题】:Error on execute postgresql function执行 postgresql 函数时出错
【发布时间】:2013-03-06 10:52:36
【问题描述】:

我有这个简单的功能:

CREATE OR REPLACE FUNCTION soundavity.perform_search_by_serie_name( in_search_text   text )
RETURNS bigint[] AS

$BODY$

DECLARE 
match_id bigint[];  

BEGIN

SELECT id INTO match_id
FROM soundavity.tv_serieslist_tbl
where id IN (   
        SELECT id 
        FROM table
        WHERE to_tsvector('english', name) @@ to_tsquery('english', in_search_text)
        )
LIMIT 10;   


RETURN match_id;

END;

但是当我尝试时

select perform_search_by_serie_name('something');

Postgres 返回:

ERROR:  array value must start with "{" or dimension information
CONTEXT:  PL/pgSQL function soundavity.perform_search_by_serie_name(text) line 8 at    SQL statement

哪里出错了?

【问题讨论】:

    标签: function postgresql stored-procedures plpgsql


    【解决方案1】:

    'SELECT id' 返回 setof bigint 而不是 bigint 数组。 试试这个:

    DECLARE 
        match_id bigint[] = '{}';
        rid bigint;
    BEGIN
        for rid in
            SELECT ... -- without INTO
        loop
            match_id:= array_append(match_id, rid);
        end loop;
    RETURN match_id;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多