title: cursor loop in PostgreSQL
body: <p>This below code is a cursor in PostgreSQL 9.0. I want to fetch my records by joining more than one table and i am getting JSON data from that join.</p>
  
  <p>So I want to loop those records and parse that json using query something like </p>
  
  <pre><code>SELECT "Dump"-&gt;'activities-steps'-&gt;0-&gt;'value' as "steps"
  FROM "ActivitySessionDump" where "Id"=42594321345021288   
  </code></pre>
  
  <p>then i have to get data from this query and insert to some other table like</p>
  
  <pre><code>insert to table name (key,value);
  </code></pre>
  
  <p>So i prepared one readonly cursor to achieve this task </p>
  
  <pre><code>begin work;
  
  DECLARE 
  sessionids INSENSITIVE no scroll CURSOR FOR 
  SELECT asn."Id",asn."UserId",asn."ActivityId",ad."Dump"
    FROM "ActivitySession" as asn inner join "ActivitySessionDump" as ad 
    on asn."Id"=ad."ActivitySessionId" 
    where asn."CreatedAt" between now() - interval '5 hours' and now() and asn."ActivityId"=1 
  for read only;
  ---- i want her loop should start and i will parse a json Dump by executing query--------
  
  --------insert record to another table---------------
  
  ---end loop-----------
  FETCH next FROM sessionids;
  CLOSE sessionids;
  COMMIT WORK;
  </code></pre>
  
  <p>Any help really appreciated.Thanks </p>