2013-03-06 91 views
0

我有這個簡單的功能:錯誤上執行PostgreSQL的功能

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 

哪裏錯誤?

回答

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;