gpt4 book ai didi

postgresql - 列 "xxxx"的默认值无法自动转换为在 Postgres DB 中键入 bool 值

转载 作者:行者123 更新时间:2023-11-29 11:37:46 24 4
gpt4 key购买 nike

我正在尝试将 brs.parts 表中的列从字符变化更新为 bool 值。到目前为止,该列的数据为 Y/N。我正在使用以下命令

ALTER TABLE brs.parts ALTER COLUMN is_dpm_scanned TYPE BOOLEAN USING is_dpm_scanned::BOOLEAN

但是我收到以下错误:

********* 错误 **********

ERROR: default for column "is_dpm_scanned" cannot be cast automatically to type boolean
SQL state: 42804

表定义是:

CREATE TABLE brs.parts (
id serial NOT NULL PRIMARY KEY,
webcrt_part_id INTEGER,
event_id INTEGER,
webcrt_job_id INTEGER,
incoming_serial_number CHARACTER VARYING(256),
outgoing_serial_number CHARACTER VARYING(256),
part_number CHARACTER VARYING(256),
tag_number NUMERIC,
is_dpm_scanned CHARACTER VARYING(1) DEFAULT 'N'::CHARACTER VARYING,
current_operation_id INTEGER,
creation_date DATE,
created_by CHARACTER VARYING(20) NOT NULL,
last_updated_date DATE,
last_updated_by CHARACTER VARYING(20) NOT NULL,
is_delete CHARACTER VARYING(1) DEFAULT 'N'::CHARACTER VARYING
);

最佳答案

在更改类型之前必须删除默认约束:

ALTER TABLE parts 
ALTER COLUMN is_dpm_scanned DROP DEFAULT,
ALTER COLUMN is_dpm_scanned TYPE BOOLEAN USING is_dpm_scanned::BOOLEAN,
ALTER COLUMN is_dpm_scanned SET DEFAULT FALSE;

另见:

关于postgresql - 列 "xxxx"的默认值无法自动转换为在 Postgres DB 中键入 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41149554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com