Refactoring one Postgres table into several tables

229 Views Asked by At

Let's say I have a table with the following columns:

id | address | city | state

Now let's say I want to take the data from that table and move it into 3 new tables:

Table 1 ("addresses"):

id | address | city_id

Table 2 ("cities"):

id | city | state_id

Table 3 ("states"):

id | state

I've seen a few answers involving data-modifying CTEs, but they're not very clear and I'm having trouble understanding how I would do something like what I described above.

0

There are 0 best solutions below