查询没有结果数据错误的目的地
query has no destination for result data error
我在`
中有以下功能
CREATE OR REPLACE FUNCTION public.get_avalable_providers(
start_day_id integer,
end_day_id integer,
number_of_days integer,
requested integer)
RETURNS SETOF provider AS
$BODY$declare
required integer;
available_product integer;
p provider;
p_id integer;
noa integer;
begin
FOR p IN SELECT * FROM provider
loop
FOR p_id, noa IN SELECT id, number_of_availables FROM product
WHERE provider_id = p.id
LOOP
required = requested/noa;
select available_product =
public.get_available_products_biggerthan(
start_day_id, end_day_id, number_of_days, required, p_id);
if available_product = number_of_days then
return next p;
exit;
end if;
END LOOP;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION public.get_avalable_providers(integer, integer, integer,
integer, integer)
OWNER TO postgres;
以上功能应该 return 一些供应商在几天内有足够数量的请求 product
它正在利用另一个函数 get_available_products_biggerthan
,我收到以下错误:
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
get_avalable_products(integer,integer,integer,integer,integer) line 15 at
SQL statement
问题
我在哪里犯错?
https://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW
The result of a SQL command yielding a single row (possibly of
multiple columns) can be assigned to a record variable, row-type
variable, or list of scalar variables. This is done by writing the
base SQL command and adding an INTO clause
尝试以下(我只修复了明显的语法):
CREATE OR REPLACE FUNCTION public.get_avalable_providers(
start_day_id integer,
end_day_id integer,
number_of_days integer,
requested integer)
RETURNS SETOF provider AS
$BODY$declare
required integer;
available_product integer;
p provider;
p_id integer;
noa integer;
begin
FOR p IN (SELECT * FROM provider)
loop
FOR p_id, noa IN (SELECT id, number_of_availables FROM product
WHERE provider_id = p.id)
LOOP
required = requested/noa;
select public.get_available_products_biggerthan(
start_day_id, end_day_id, number_of_days, required, p_id) INTO available_product ;
if available_product = number_of_days then
return next p;
exit;
end if;
END LOOP;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
我在`
中有以下功能CREATE OR REPLACE FUNCTION public.get_avalable_providers(
start_day_id integer,
end_day_id integer,
number_of_days integer,
requested integer)
RETURNS SETOF provider AS
$BODY$declare
required integer;
available_product integer;
p provider;
p_id integer;
noa integer;
begin
FOR p IN SELECT * FROM provider
loop
FOR p_id, noa IN SELECT id, number_of_availables FROM product
WHERE provider_id = p.id
LOOP
required = requested/noa;
select available_product =
public.get_available_products_biggerthan(
start_day_id, end_day_id, number_of_days, required, p_id);
if available_product = number_of_days then
return next p;
exit;
end if;
END LOOP;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION public.get_avalable_providers(integer, integer, integer,
integer, integer)
OWNER TO postgres;
以上功能应该 return 一些供应商在几天内有足够数量的请求 product
它正在利用另一个函数 get_available_products_biggerthan
,我收到以下错误:
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
get_avalable_products(integer,integer,integer,integer,integer) line 15 at
SQL statement
问题 我在哪里犯错?
https://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW
The result of a SQL command yielding a single row (possibly of multiple columns) can be assigned to a record variable, row-type variable, or list of scalar variables. This is done by writing the base SQL command and adding an INTO clause
尝试以下(我只修复了明显的语法):
CREATE OR REPLACE FUNCTION public.get_avalable_providers(
start_day_id integer,
end_day_id integer,
number_of_days integer,
requested integer)
RETURNS SETOF provider AS
$BODY$declare
required integer;
available_product integer;
p provider;
p_id integer;
noa integer;
begin
FOR p IN (SELECT * FROM provider)
loop
FOR p_id, noa IN (SELECT id, number_of_availables FROM product
WHERE provider_id = p.id)
LOOP
required = requested/noa;
select public.get_available_products_biggerthan(
start_day_id, end_day_id, number_of_days, required, p_id) INTO available_product ;
if available_product = number_of_days then
return next p;
exit;
end if;
END LOOP;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;