2016-05-14 2 views
0

ich eine Schleife in einer Funktion implementieren wollen, aber ich erhalte diesen Fehler:SELECT hebt Ausnahme in PL/pgSQL Funktion

ERROR query has no destination for result data

Der Code:

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); 

Warum? Wie man es repariert?

+0

http://stackoverflow.com/questions/23946735/postgresql-query-has -no-Ziel-für-Ergebnis-Daten –

+0

@ManfreedRadlwimmer, und was? Dies ist absolut nicht die Antwort. – Vyacheslav

+3

'SELECT 1;' Ich denke, er meint das. "Abfrage" = "SELECT 1;" "hat kein Ziel". –

Antwort

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; 

Sofern Sie das Ergebnis zuweisen, ersetzen

SELECT 1; 

mit

PERFORM 1; 
Verwandte Themen