[英]What's the difference between default and set default in Postgres?
I am kind of new to Postgres and I'm trying to use the following query in Postgres: 我是Postgres的新手,并且尝试在Postgres中使用以下查询:
alter table tablename add column col1 enum('r', 'g', 'b') not null set default 'r';
It is giving me an error. 这给我一个错误。 When I changed it to default
instead of set default
, it worked fine. 当我将其更改为default
而不是set default
,它运行良好。
Just wondering what the reason might be! 只是想知道原因可能是什么!
As for "why does it work"? 至于“为什么起作用”?
I suspect that you were using it in one of the following two ways: 我怀疑您是通过以下两种方式之一使用它的:
alter table tablename add column col1 text default 'r';
and 和
alter table tablename alter column col1 set default 'r';
Note that the former alters the table by adding a column with a default value, while in the latter, the column already exists and you alter the column by setting a default value. 请注意,前者通过添加具有默认值的列来更改表,而后者则已经存在该列,并且您可以通过设置默认值来更改该列。
You can find more information about defaults in create table and alter table 您可以在创建表和更改表中找到有关默认值的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.