如何重命名 table 以及 Vertica 中的投影?

How to rename a table along with projections in Vertica?

我必须更改 Vertica table 中的许多列,并决定完全删除 table 并创建一个新列。我还需要 'undo' 脚本准备好在需要时还原更改(使用 mybatis 迁移)。

这是我的计划:

rename mytable to mytable_backup

create mytable
create projection mytable_super (as select from mytable)


--undo
drop mytable if exists
rename mytable_backup to mytable

原来mytable也是用投影创建的。上面的脚本报错说投影已经存在。

 DBCException: SQL Error [4482] [42710]: [Vertica][VJDBC](4482) ROLLBACK:         Projection with base name "mytable_super" already exists

我相信当我重命名原始 table 时,底层投影没有被重命名。

用垂直投影重命名 table 的最佳方法是什么?或者备份 table 并还原的最佳方法是什么?

您还需要 rename the projections

alter projection mytable_super rename to mytable_super_backup;

重命名一个table,上面的答案就是那个。

重命名投影的一种方法是将投影放入 SQL 文件中。例如:

 select CONCAT(CONCAT(projection_schema,'.'),projection_name) from projections where projection_schema like '%one_table%'

然后修改成下面的SQL并执行(别忘了运行刷新): https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/AdministratorsGuide/Projections/UpdatingProjectionsUsingRefresh.htm

一旦你有了SQL,你就可以\i /path/of/sql(在vertica shell里面)或者你可以/opt/vertica/bin/vsql -f /path/to/sql/that.sql -U vertica_user -w vertica_passwd