I have a table with approximately 2 million records in old_parent that I need to split into the table structure below it.
I've tried using something like a CTE using a method I saw here.
Example:
WITH address_ins AS (
  INSERT INTO address (address)
  VALUES op.address
  RETURNING id
  )
, parent_ins AS (
  INSERT INTO parent (info, parent_address_id)
  VALUES (op.info, address_ins.id)
, child_1_ins AS (
  INSERT INTO child_1 (thing_1, parent_id)
  VALUES (op.thing_1, parent_ins.parent_id)
)
  ... So On So Forth
SELECT * FROM old_parent op;
But this method does not work because the statements don't recognize op. Am I just missing something small or is there a better way to do this?

 
    