Postgres ALTER TABLE的问题 [英] Problem with Postgres ALTER TABLE

查看:231
本文介绍了Postgres ALTER TABLE的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在postgre中的ALTER TABLE有一个问题.我想更改varchar列的大小.当我尝试执行此操作时,它表示视图依赖于该列.我不能放弃观点,因为其他事物取决于它.除了删除所有内容并重新创建以外,还有其他方法吗?

I have one problem with the ALTER TABLE in postgre. I want to change size of the varchar column. When I try to do this, It says that the view is dependent on that column. I can't drop the view because comething else is dependent on it. Is there any other way than to drop everything and recreate it again?

我刚刚找到一个选项,那就是从视图中删除连接的表,当我不更改返回的列时,可以做到这一点.但是,仍然需要更改更多视图.我有什么好说的,应该推迟并通过提交检查吗?

I just found one option, which is to remove the table joining from the view, when I will not change the returned columns, I can do that. But still, there is more views I'll need to change. Isn't there anything how can I say that it should be deferred and checked with commit?

推荐答案

我遇到了这个问题,找不到任何解决方法.不幸的是,据我所知,必须删除视图,更改基础表上的列类型,然后重新创建视图.这完全可以在单个交易中发生.

I have run into this problem and couldn't find any way around it. Unfortunately, as best I can tell, one must drop the views, alter the column type on the underlying table, and then recreate the views. This can happen entirely in a single transaction.

约束推迟不适用于此问题.换句话说,即使SET CONSTRAINTS ALL DEFERRED对此限制也没有影响.具体来说,约束延迟不适用于试图更改视图基础列的类型时打印ERROR: cannot alter type of a column used by a view or rule的一致性检查.

Constraint deferral doesn't apply to this problem. In other words, even SET CONSTRAINTS ALL DEFERRED has no impact on this limitation. To be specific, constraint deferral does not apply to the consistency check that prints ERROR: cannot alter type of a column used by a view or rule when one tries to alter the type of a column underlying a view.

这篇关于Postgres ALTER TABLE的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆