title: Usage of variables in an UPDATE (edited)
body: <p>Consider this :</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION search_and_replace_everywhere(regex TEXT,
                                                           replacement TEXT)
  RETURNS VOID AS
  $$
  DECLARE
      matching search_columns_result;
  BEGIN
      FOR matching IN SELECT *
                      FROM search_columns(regex)
          LOOP
              RAISE NOTICE 'schemaname: %s, tablename: %s, columnname: %s, rowctid: %s', quote_ident(matching.schemaname), quote_ident(matching.tablename), quote_ident(matching.columnname), quote_ident(matching.rowctid);
              UPDATE ${matching.schemaname}.${matching.tablename} SET ${matching.columnname} = REPLACE(${matching.columnname}, regex, replacement);
          END LOOP;
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>How am I supposed to write this UPDATE ? I can't find a way to insert variable value inside query to build it.</p>
  
  <p>EDIT, I think I find the way ! But I still miss something because :</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION search_and_replace_everywhere(regex TEXT,
                                                           replacement TEXT)
      RETURNS VOID AS
  $$
  DECLARE
      matching search_columns_result;
  BEGIN
      FOR matching IN SELECT *
                      FROM search_columns(regex)
          LOOP
              RAISE NOTICE 'schemaname: %s, tablename: %s, columnname: %s, rowctid: %s', QUOTE_IDENT(matching.schemaname), QUOTE_IDENT(matching.tablename), QUOTE_IDENT(matching.columnname), QUOTE_IDENT(matching.rowctid);
              EXECUTE format('UPDATE %I SET %I = REPLACE(%I, %I, %I)', matching.schemaname || '.' || matching.tablename,
                             matching.columnname, matching.columnname, regex, replacement);
          END LOOP;
  END ;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>generates : </p>
  
  <blockquote>
    <p>ERROR:  relation "public.groups_oxusers" does not exist LINE 1: UPDATE
    "public.groups_oxusers" SET group_name = REPLACE(grou...</p>
  </blockquote>
  
  <p>Why is there double quotes around table name but not around column name and how to remove it?</p>