How to change the schema by arg text in postgres procedure
问题 CREATE OR REPLACE FUNCTION newfunction (Schema1 text, Schema2 text) RETURNS integer LANGUAGE plpgsql SECURITY DEFINER AS $function$ . . . insert into [Schema1].table (name,phone,address,......) select name,phone,address,..... from [Schema2].table where....; I want to change the schema by arg text is this possible to do this? 回答1: You'll have to use dynamic SQL throughout: EXECUTE format( E'INSERT INTO %I.tab (...)\n' 'SELECT ... FROM %I.tab WHERE ...', schema1, schema2 ); 来源: https:/