I have a function in Postgresql and I want to select from a table and insert into another table.
CREATE OR REPLACE FUNCTION "public"."update_table"("table_name" varchar, "key_col" varchar, "title_col" varchar)
RETURNS "pg_catalog"."bool" AS $BODY$
DECLARE
temprow record;
BEGIN
FOR temprow IN
EXECUTE 'SELECT '|| table_key ||', '|| table_title ||' FROM '|| table_name
LOOP
EXECUTE 'INSERT INTO coding(title, code,"parent_code") VALUES ('|| temprow.title_col ||', '|| temprow.key_col ||', 2);';
END LOOP;
RETURN 't';
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
there is an error for accessing temprow value with key_col variable , how can I access to this fields?
ERROR: record "temprow" has no field "table_title"