I have the following situation which generates a OID error when retriving data from the table table_generated_by_my_other_function that is generated by the first part of the loop when the nested function my_other_function() is called. How can this be fixed?
The function function my_other_function() generates a table with just one row of data with 7 columns, so could this results be stored or returned in some other way? Do I get the error becuase the table doesn't exists without a commit?
function my_other_function() works OK on its own.
CREATE OR REPLACE FUNCTION my_function() RETURNS varchar AS $$
DECLARE
row_data RECORD;
helper int;
BEGIN
EXECUTE '
DROP TABLE IF EXISTS my_table_loop_result;
';
EXECUTE '
CREATE TABLE my_table_loop_result (
var1 varchar, var2 varchar, var3 varchar, var4 int,
var5 varchar, var6 varchar, var7 int)
';
FOR row_data IN SELECT var_x1, var_x2 FROM my_table_too
LOOP
SELECT my_other_function(row_data.var_x1, row_data.var_x2) INTO helper; --Returns "1" if OK
INSERT INTO my_table_loop_result(var1,var2,var3,var4,var5,var6.var7)
SELECT
var1,var2,var3,var4,var5,var6,var7
FROM table_generated_by_my_other_function --OID ERROR!
WHERE var1 = row_data.var1;
END LOOP;
RETURN 1;
END;
$$ LANGUAGE plpgsql;