我在一台服务器上有两个postgres数据库。
我需要从一个数据库中提取记录并将它们放入另一个数据库中。这是我的工作查询。
insert into "tblInvInfo"
select "iiInvNum", "iiItemCode","iiUnitMeasure", "iiUnitQuantity",
"iiPrice", "iiUnits" from
dblink ('dbname=dbESM', 'SELECT * from "tblInvInfo" ')
AS invinfo ("iiInvNum" varchar, "iiItemCode" varchar,
"iiItemName" varchar, "iiUnitMeasure" varchar, "iiUnitQuantity" numeric,
"iiPrice" numeric, "iiUnits" numeric)
基本上,这会从 dbESM 的 tblInvInfo 中提取记录,并将它们放在 dbESMTemp
的相同表中现在,要求...... tblInvMaster 包含发票的主要详细信息(并包含日期),而 tblInvInfo 包含项目的详细信息。
我只需要提取符合 tblInvMaster 中特定条件的 tblInvInfo 记录。我认为这是通过简单的内连接查询完成的。所以这就是我的尝试:
insert into "tblInvInfo"
select "iiInvNum", "iiItemCode","iiUnitMeasure",
"iiUnitQuantity", "iiPrice", "iiUnits" from
dblink ('dbname=dbESM', 'SELECT "iiInvNum", "iiItemCode",
"iiUnitMeasure", "iiUnitQuantity", "iiPrice", "iiUnits" from
(select "tblInvInfo".* from (select * from "tblInvMaster"
where "invDate" between \'2014-08-01\' and \'2014-10-17\') invmaster
inner join "tblInvInfo" on "invInvNum" = "iiInvNum" ) filteredinvinfo ')
AS invinfo ("iiInvNum" varchar, "iiItemCode" varchar,
"iiItemName" varchar, "iiUnitMeasure" varchar,
"iiUnitQuantity" numeric, "iiPrice" numeric, "iiUnits" numeric);
对于上述查询,我收到以下错误:
错误:语法错误在或附近" 2014"第7行:其中" invDate" 在2014-08-01之间\#39;和\“#2014; 2014-10-17 \')... ^
我的加入是正确的,但我对查询有三个疑问:
真正感谢任何帮助解决这个问题。