title: postgresql create function dynamically insert value into different table
body: <p>I want to create a function that can dynamically insert any data type value into any table and multiple columns. But my function can only insert one value to one column: </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.dynamic_insert(
                    tablename character varying,
                    columname character varying,
                    datatype character varying,
                    valuee text
                                                )
  RETURNS void
  LANGUAGE 'plpgsql'
  COST 100
  VOLATILE AS
  $BODY$
  begin
  
      Execute format('insert into %I ('||columname||') 
                 values (cast($1 as '||datatype||'))',tablename,columname);
  
  end;
  $BODY$;
  </code></pre>
  
  <p>Can any one help?</p>