title: Convert string to column name
body: <p>I'm trying to write a simple postgres function which looks more or less like that:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION USER_TOTALS(column_name varchar, in_t users) RETURNS float AS $$
    DECLARE
      sum float;
    BEGIN
      sum = (SELECT SUM($1) FROM jobs WHERE jobs.technician_id = in_t.id);
      RETURN sum;
    END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>And i need to use it like that:</p>
  
  <pre><code>SELECT users.*, USER_TOTALS('jobs.price', users.*) AS total_price_value FROM users;
  </code></pre>
  
  <p>Hovewer, that's obviously not working cause <code>SUM()</code> function expects to get a column name but my code passes a varchar to it, so the error says:</p>
  
  <pre><code>Function sum(character varying) does not exist
  </code></pre>
  
  <p>The question is - can i somehow cast a varchar variable to column name var type? I've been googling for this thing for about 2 hours now and i have no idea how can i make that happen.</p>