我有以下功能(返回一组自定义类型)
CREATE OR REPLACE FUNCTION myfunction(in_myvar integer)
RETURNS SETOF my_type AS
$BODY$
DECLARE
v_data my_type%rowtype;
v_another_var text;
BEGIN
FOR v_data IN (
-- I want to be able to do a SELECT INTO v_another_var in each iteration
-- of the loop, ideally so I can use this value throughout the select
-- statement e.g.:
-- SELECT INTO v_another_var regex_replace(col3, '[^a-zA-Z0-9 ]', '');
SELECT DISTINCT
col1
col2,
-- v_another_var AS some_column
-- etc.
-- perhaps use this v_another_var again here
-- as part of something else.
FROM mytable
WHERE v_another_var = 'test' + some_function() = 'something'
-- want to use the variable again here.
) LOOP
RETURN NEXT v_data;
END LOOP;
RETURN;
$BODY$
是否可以分配一个变量并以这种方式在每个选择语句中作为循环的一部分使用它?即使这是可能的,SELECT INTO 语句是否可以在我拥有它的地方工作(col3 可以访问吗?)
postgres 有没有办法实现这种变量的使用?