2016-05-14 49 views
0

我想實現一個函數內部循環,但我收到此錯誤:SELECT產生異常在PL/pgSQL函數

ERROR query has no destination for result data

代碼:

CREATE OR REPLACE FUNCTION my_function(ill int, ndx_ bigint) RETURNS int AS 
$$ 
DECLARE 
    found_id int; 
BEGIN 
    FOR found_id IN 1..25 LOOP 
     SELECT 1; 
    END LOOP; 
    RETURN 1; 
END; 
$$ LANGUAGE plpgsql; 

SELECT my_function(0,79); 

爲什麼?如何解決它?

+0

http://stackoverflow.com/questions/23946735/postgresql-query-has -no-destination-for-result-data –

+0

@ManfredRadlwimmer,以及什麼?這完全不是答案。 – Vyacheslav

+3

'SELECT 1;'我認爲他是這個意思。 「查詢」='選擇1;'「沒有目的地」。 – 2016-05-14 19:13:01

回答

1

The manual instructs:

Sometimes it is useful to evaluate an expression or SELECT query but discard the result, for example when calling a function that has side-effects but no useful result value. To do this in PL/pgSQL, use the PERFORM statement:

PERFORM query; 

除非您分配的結果,更換

SELECT 1; 

PERFORM 1;