Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update column using dblink

I am using below reference to update 2 columns (customer name, service) at table cust_eq_memory_dy.

loopback at table msrouterlistfinal2 will match address at cust_eq_memory_dy.

Can someone help me on this as I got the syntax error at or near "FROM"?

Update between 2 databases using dblink not working

UPDATE cust_eq_memory_dy B 
SET customername = A.customername 
WHERE B.ipaddress = A.loopbackip 
FROM ( 
  SELECT *
  FROM DBLINK ( 'host= 10.X.80.160 user=123 password=123 dbname=postgres',
'select customername, serviceid, loopbackip FROM msrouterlistfinal2 ')
 as temp (
 customername character varying (100),
 serviceid character varying (50),
 loopbackip character varying (30) )
 )A
like image 944
Samila Avatar asked Aug 23 '26 10:08

Samila


1 Answers

if you are using postgres I highly recommend you to use the WITH sentence.

    WITH A as ( SELECT * FROM DBLINK ( 'host= 10.X.80.160 user=123 password=123 dbname=postgres', 'select customername, serviceid, loopbackip FROM msrouterlistfinal2 ') as temp ( customername character varying (100), serviceid character varying (50), loopbackip character varying (30) ) )
UPDATE cust_eq_memory_dy B SET customername = (SELECT A.customername FROM A WHERE B.ipaddress = A.loopbackip);

Check this link for more information. https://www.postgresql.org/docs/8.4/static/queries-with.html

like image 50
Oscar Ivan Martinez Arce Avatar answered Aug 26 '26 23:08

Oscar Ivan Martinez Arce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!