title: Passing column names dynamically for a record variable in PostgreSQL
body: <p>Using PostgreSQL, column values from a table for 1st record are stored in a record variable. for ex: let the variable be: <code>recordvar</code></p>
  
  <pre><code>recordvar.columnname
  </code></pre>
  
  <p>gives the value of the column name specified. I will define the <code>columname</code> in a variable:</p>
  
  <pre><code>var := columnname
  </code></pre>
  
  <p>In place of <code>columnname</code> if I replace with the variable i.e. <code>recordvar.var</code>, it is not working.</p>
  
  <p>Please let me know how to proceed in this situation. Following is the sample code:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION getrowdata(id numeric, table_name character varying)
  RETURNS SETOF void AS
  $BODY$ 
  DECLARE
  
  srowdata record;
  reqfield character varying;
  value numeric;
  
  
  BEGIN
  
  RAISE NOTICE 'id: %',id; 
  reqfield:= 'columnname';
  
  EXECUTE 'select * from datas.'||table_name||' WHERE id = '||id into srowdata;
  
  RAISE NOTICE 'srowdata: %',srowdata; 
  
  RAISE NOTICE 'srowdatadata.columnname: %',srowdata.columnname;
  
  value:= srowdata.reqfield;
  
  RAISE NOTICE 'value: %',value;
  
  
  END;
  $BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
  </code></pre>