不包括 Postgres 复制表架构 is_null 约束

问题描述

我有一个包含 ff 列和约束的表:

create table newtable(
    id int4 not null primary key,lastname varchar(50) not null,firstname varchar(50) not null,middlename varchar(50) not null
)

我正在开发一个工作流脚本 (KNIME),它将测试从源到目标的架构。 所以我使用ff。代码

CREATE TABLE xtable 
AS TABLE newtable;

当我检查 is_null 约束时,它被设置为“是”(但在原始表中,它被设置为“否”)。如何使用上述代码脚本包含约束?

解决方法

目前的方法似乎无法实现。我知道的最佳选择是以下查询:

CREATE TABLE xtable (LIKE newtable INCLUDING ALL);

INSERT INTO xtable SELECT * FROM newtable;

您可以阅读有关此语法 here 的信息。