以下函数在运行时会报错
我注意到,当我删除这条线时AND t.image_id = mviews.image_id
,它会起作用。
即使我将 mviews.image_id 更改为常数,它也可以工作
我在想我没有正确引用循环参数?
0000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000
CREATE OR REPLACE FUNCTION test() RETURNS void AS $$
DECLARE
mviews RECORD;
BEGIN
FOR mviews IN
SELECT image_id FROM image_index_1205 WHERE image_type = '01' LIMIT 3
LOOP
copy (
SELECT encode(decode(image, 'base64'), 'hex')
FROM image_index_1205 t
WHERE image_type = '01'
AND t.image_id = mviews.image_id
LIMIT 1
)
TO
'/tmp/test.hex';
END LOOP;
END;
$$ LANGUAGE plpgsql;
0000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000
********** Error **********
ERROR: there is no parameter $1
SQL state: 42P02
Context: SQL statement "copy ( SELECT encode(decode(image, 'base64'), 'hex') FROM image_index_1205 t WHERE image_type = '01' AND t.image_id = $1 LIMIT 1 ) TO '/tmp/test.hex'"
PL/pgSQL function "test" line 7 at SQL statement
0000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000