PostgreSQL: nested loop
Is it possible to have a loop within another loop? (nested loops) in postgres. Something similar to below:
WHILE rowCounter < totalRows LOOP
   开发者_运维知识库 FETCH NEXT FROM retailerIdCursor INTO retailerID;
    --FOR i IN 1..8 LOOP
    --WHILE i < 8 LOOP
    LOOP
        UPDATE sales_fact
        SET retailer_id = retailerID
        WHERE sales_id = rowCounter;
        EXIT WHEN i > 8;
    END LOOP;
    rowCounter = 1+ rowCounter;
END LOOP;
I fail to see why you cannot just write
UPDATE sales_fact
   SET retailer_id = retailerID
WHERE sales_id IN(1,2,3,4,5,6,7,8);
as Frank has suggested.
Depending on the statement that selects the retailerId, you might not even need the outer loop as well.
You can look at postgresql documentation. http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html
 加载中,请稍侯......
      
精彩评论