我有以下功能(返回一組自定義類型的)變量在PostgreSQL的循環
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語句作爲這樣一個循環的一部分嗎?即使這是可能的話,SELECT INTO語句的工作,我把它(將COL3可以訪問?)
是否有Postgres的方式來實現這種變量使用的?
對不起。我並沒有故意試圖讓這個問題變得複雜/混亂 - 我想我並不真正瞭解這個問題如何運作。 – 2012-04-20 21:30:36