首页 > 解决方案 > 使用 UNIQUE 约束时如何插入不同的列

问题描述

我有这张桌子:

在此处输入图像描述

car-model 和 motor-model 都有独特的约束。

我尝试首先插入我所有的汽车模型。所以

Car-model
Volkwgen
Tesla

然后我想添加电机模型

Motor-model
PX
GX

但由于独特的约束,我得到 [Null] 值

即使没有唯一约束,我也会得到 [Null] 值。

标签: sqlpostgresql

解决方案


这是你想要做的吗?

insert into car_models (car_model, motor_model)
    values ('Volkswagen', 'PX'),
           ('Tesla', 'GX');

推荐阅读