【发布时间】:2020-10-03 10:24:00
【问题描述】:
表结构:
旧表结构:
新表结构:
查询:
INSERT INTO hotel (id, name, hotel_type, active, parent_hotel_id)
SELECT id, name, hotel_type, active, parent_hotel_id
FROM dblink('demopostgres', 'SELECT id, name, hotel_type, active, parent_hotel_id FROM hotel')
AS data(id bigint, name character varying, hotel_type character varying, active boolean, parent_hotel_id bigint);
出现以下错误:
错误:“created_by”列中的空值违反非空约束 详细信息:失败行包含 (1, Test Hotel, THREE_STAR, t, null, 空,空,空,空,空)。 SQL状态:23502
我尝试插入其他必需的列
注意:created_by 为 Jsonb
created_by = '{
"id": 1,
"email": "tes@localhost",
"login": "test",
"lastName": "Test",
"firstName": "Test",
"displayName": "test"
}'
created_date = '2020-02-22 16:09:08.346'
如何在从旧表中移动数据时传递 created_by 和 created_date 列的默认值?
【问题讨论】:
-
创建新表时定义默认值。
-
表已经创建,我正在将数据从旧表移动到新表,现在我想传递两列(created_by,created_date)的默认值,其余部分来自旧表(见上面的查询)
标签: sql json postgresql