通过检查Postgresql中另一个表的某些约束将数据插入到表中

时间:2019-04-15 15:24:51

标签: postgresql select insert subquery insert-select

我有两个桌子。

  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);

0 个答案:

没有答案