SELECT 在 PL/pgSQL 函数中引发异常
SELECT raises exception in PL/pgSQL function
我想在一个函数内实现一个循环,但我收到这个错误:
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 );
为什么?如何解决?
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;
我想在一个函数内实现一个循环,但我收到这个错误:
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 );
为什么?如何解决?
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 thePERFORM
statement:PERFORM query;
除非您分配结果,否则替换
SELECT 1;
和
PERFORM 1;