我想将整个where条件作为参数传递给Postgrel。
有可能吗?我已经创建了类似的程序,
CREATE OR REPLACE FUNCTION public.pro_select_all_item_query_builder_data(IN cond character varying)
RETURNS TABLE(id integer, name character varying) AS
$BODY$
BEGIN
FOR id, name IN
SELECT product.id, product.name FROM product WHERE cond
.............
并称呼它,
SELECT *
FROM pro_select_all_item_query_builder_data('product.status_id = 1')
显示错误:WHERE的参数必须为布尔型,而不是字符变化
您能支持我解决这个问题吗?
答案 0 :(得分:0)
请确保cond
具有有效条件,否则将引发语法错误。
FOR id, name IN
EXECUTE ('SELECT product.id, product.name FROM product WHERE ' || cond)
LOOP
....
END LOOP;