postgresql 更改列类型并设置非空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16197236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:09:38  来源:igfitidea点击:

Change column type and set not null

postgresql

提问by Oto Shavadze

How do you change the column type and also set that column to not nulltogether?

您如何更改列类型并将该列设置not null在一起?

I am trying:

我在尝试:

ALTER TABLE mytable ALTER COLUMN col TYPE character varying(15) SET NOT NULL

This returns an error.

这将返回一个错误。

What is the right syntax?

什么是正确的语法?

回答by Federico Razzoli

This should be correct:

这应该是正确的:

ALTER TABLE mytable
    ALTER COLUMN col TYPE character varying(15),
    ALTER COLUMN col SET NOT NULL