I'm trying to generate new IDs for a large table. The ID's have to be consecutive and need to start at 0 (So I can't use sequence). What I come up with so far is the following function:
CREATE OR REPLACE FUNCTION genIds() RETURNS integer AS $$
DECLARE
edge RECORD;
i INTEGER := 0;
BEGIN
FOR edge IN SELECT * FROM network LOOP
UPDATE network SET id = i WHERE id = edge.id;
i := i + 1;
END LOOP;
RETURN i;
END;
$$ LANGUAGE plpgsql;
I would much rather like to not care about id = edge.id since I don't really care about the id's anyway. Is there a way to avoid having count(network) updates?
Cheers, Daniel
0:create sequence foo_seq start with 0 minvalue 0;