INSERT INTO ip_cpu_mn(datetime, resource_id, ipaddress,cpu_utilization)
SELECT cpu_mn.datetime, resource_id, ipaddress, cpu_utilization
FROM dblink('host=10.0.32.175 user=postgres password=postgres dbname=TNPM_EXT','SELECT datetime, resource_id, ipaddress,cpu_utilization FROM ext_ip.cpu_mn WHERE datetime >=(now() - interval '30 minutes')')
AS cpu_mn(datetime timestamp without time zone, resource_id numeric(10,0), ipaddress character varying(20), sysname character varying(100), cpu_utilization numeric(6,2))
您运行以上查询并获得以下错误:
psql.bin:/home/samila/SQL_SMZ/ip_cpu_mn1.sql:15:错误:语法错误 在或附近" 30"第6行:... xt_ip.cpu_mn WHERE datetime> =(now() - 间隔' 30分钟' ...
任何人都可以帮助我吗?我尝试过很多方法,但同样的错误仍然有错误。
答案 0 :(得分:0)
嫌疑人在您的查询中是单引号('
)(ERROR: syntax error at or near "30"
非常清楚),您需要在此处添加两个引号now() - interval ''30 minutes''
INSERT INTO ip_cpu_mn(datetime, resource_id, ipaddress,cpu_utilization)
SELECT cpu_mn.datetime, resource_id, ipaddress, cpu_utilization
FROM dblink('host=10.0.32.175 user=postgres password=postgres dbname=TNPM_EXT','SELECT datetime, resource_id, ipaddress,cpu_utilization FROM ext_ip.cpu_mn WHERE datetime >=(now() - interval ''30 minutes'')')
AS cpu_mn(datetime timestamp without time zone, resource_id numeric(10,0), ipaddress character varying(20), sysname character varying(100), cpu_utilization numeric(6,2))