首页 > 解决方案 > 通过检查 Postgresql 中另一个表的某些约束来将数据插入到表中

问题描述

我有两张桌子;

  1. route_info: (routeinfo_id(主键),route_src,route_dest,driver_id(外键)

  2. route_details:(routedetails_id(主键),route_latitude,route_longitude,route_address,routeinfo_id(外键))。

我在尝试通过检查 route_info 表的某些约束将数据插入到 route_details 表时遇到错误。

我的查询:

INSERT INTO route_details (route_latitude,route_longitude,routeinfo_id) VALUES (78.23,27.54,1) 
SELECT * 
FROM route_details
WHERE route_address='CNG Station,Agartala' 
AND routeinfo_id IN (SELECT routeinfo_id 
                     FROM  route_info 
                      WHERE route_info.route_source='Udaipur' 
                        AND route_info.route_destination='Agartala' 
                        and route_info.driver_id=1);

标签: postgresqlselectinsertsubqueryinsert-select

解决方案


推荐阅读