Guest User

Untitled

a guest
May 2nd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. INSERT INTO localdb_image select * from
  2. dblink('host=10.1.1.1
  3. user=user
  4. password=password
  5. dbname=oat', 'SELECT e.* FROM image e JOIN archived f ON e.image_id=f.image_id AND e.dd=f.dd') tt(
  6. id int ,
  7. drive_id character varying(255) ,
  8. ) ;
  9.  
  10. WHERE NOT EXISTS (SELECT 1 from localdb_image ei where ei.id = e.id)
  11.  
  12. create materialized view mv_localdb_image as select * from
  13. dblink('host=10.1.1.1
  14. user=user
  15. password=password
  16. dbname=oat', 'SELECT e.* FROM image e JOIN archived f ON e.image_id=f.image_id AND e.dd=f.dd') tt(
  17. id int ,
  18. drive_id character varying(255) ,
  19. ) ;
  20.  
  21. insert into localdb_image select * from mv_localdb_image mv where not exists (
  22. select 1 from localdb_image ii where ii.id=mv.id)
  23.  
  24. -- pseudocode
  25. insert into localdb_image
  26. select *
  27. from dblink(...) tt (...)
  28. on conflict(id) do nothing;
Add Comment
Please, Sign In to add comment