plpgsql: a procedure that will do only update is returning ERROR: query has no destination for result data
plpgsql: a procedure that will do only update is returning ERROR: query has no destination for result data
我正在尝试在 plpgsql 中创建一个仅 运行 一次的过程(或查询),这是我目前所做的:
create or replace procedure transfer()
LANGUAGE plpgsql as
$$
declare
cur refcursor;
trans record;
_datum timestamp;
_price integer;
BEGIN
open cur FOR
select blocknumber, "timestamp"
from transactions
group by blocknumber, "timestamp"
order by blocknumber;
loop
fetch cur into trans;
exit when not found;
select _price = "value"
from public."BNBUSDT"
where datum > trans.timestamp
order by datum
limit 1;
update public.transactions
set "PriceK" = _price
where blocknumber = trans.blocknumber
and contract_adresa_kupljenog = '1'
and "timestamp" = trans.timestamp;
end loop;
close cur;
return;
END
$$ ;
现在,当我 运行 这个过程时,我得到了这个错误:
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT: PL/pgSQL function transfer() line 20 at SQL statement
SQL state: 42601
第 20 行是
exit when not found;
如何让它工作?
select _price = "value"
此处您正在尝试 return 一个布尔值,指示这些值是否相等。该布尔结果没有目的地,因此出现错误消息。
你想要:
select "value" into _price
我正在尝试在 plpgsql 中创建一个仅 运行 一次的过程(或查询),这是我目前所做的:
create or replace procedure transfer()
LANGUAGE plpgsql as
$$
declare
cur refcursor;
trans record;
_datum timestamp;
_price integer;
BEGIN
open cur FOR
select blocknumber, "timestamp"
from transactions
group by blocknumber, "timestamp"
order by blocknumber;
loop
fetch cur into trans;
exit when not found;
select _price = "value"
from public."BNBUSDT"
where datum > trans.timestamp
order by datum
limit 1;
update public.transactions
set "PriceK" = _price
where blocknumber = trans.blocknumber
and contract_adresa_kupljenog = '1'
and "timestamp" = trans.timestamp;
end loop;
close cur;
return;
END
$$ ;
现在,当我 运行 这个过程时,我得到了这个错误:
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT: PL/pgSQL function transfer() line 20 at SQL statement
SQL state: 42601
第 20 行是
exit when not found;
如何让它工作?
select _price = "value"
此处您正在尝试 return 一个布尔值,指示这些值是否相等。该布尔结果没有目的地,因此出现错误消息。
你想要:
select "value" into _price