Replace the table with a view; the view is identical for now:
cyberdyne=> BEGIN;
BEGIN
cyberdyne=*> ALTER TABLE foo1 RENAME TO foo2;
ALTER TABLE
cyberdyne=*> CREATE VIEW foo1 AS SELECT bar, baz, quux FROM foo2;
ALTER VIEW
cyberdyne=*> COMMIT;
COMMIT
Now recreate the view to have both the old name and the new name for easy migration (applications using SELECT * will have bad time)
cyberdyne=> BEGIN;
BEGIN
cyberdyne=*> DROP VIEW foo1;
DROP VIEW
cyberdyne=*> CREATE VIEW foo1 AS SELECT bar, baz, comment AS quux, comment FROM foo2;
CREATE VIEW
cyberdyne=*> COMMIT;
COMMIT
cyberdyne=> SELECT * FROM foo1;
bar | baz | quux | comment
-----+--------------------------------+---------+---------
1 | {} | |
2 | {"service_name":null} | -- | --
3 | {"service_name":""} | minus | minus
4 | {"service_name":"jeff"} | ++ | ++
5 | {"service_name":{"nested":10}} | postfix | postfix
6 | {"galaxy":10} | scale | scale
7 | {"reg":"x"} | verbose | verbose
(7 rows)
Once the application has been updated to change all queries to use comment instead of quux, get rid of the view and rename the table back to the original name:
cyberdyne=> BEGIN;
BEGIN
cyberdyne=*> DROP VIEW foo1;
DROP VIEW
cyberdyne=*> ALTER TABLE foo2 RENAME TO foo1;
ALTER TABLE
cyberdyne=*> COMMIT;
COMMIT
cyberdyne=> SELECT * FROM foo1;
bar | baz | comment
-----+--------------------------------+---------
1 | {} |
2 | {"service_name":null} | --
3 | {"service_name":""} | minus
4 | {"service_name":"jeff"} | ++
5 | {"service_name":{"nested":10}} | postfix
6 | {"galaxy":10} | scale
7 | {"reg":"x"} | verbose
(7 rows)
Create dummy table and real data
Replace the table with a view; the view is identical for now:
Make sure the view acts like the table
Observe the columns in our view before and after renaming a column in the table
Then observe the data
Now recreate the view to have both the old name and the new name for easy migration (applications using
SELECT *
will have bad time)Once the application has been updated to change all queries to use
comment
instead ofquux
, get rid of the view and rename the table back to the original name: