Advertisement
fedorm

Untitled

May 14th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.88 KB | None | 0 0
  1. do $$
  2.     declare r record;
  3. begin
  4.  
  5.     raise notice 'do connect gavno';
  6. perform dblink_connect('host=9.6.24.188 dbname=set user=postgres password=#Pos324011');
  7.     raise notice 'posle connect gavno';
  8. perform dblink_open('cards_segments', 'select * from cards_segments limit 5');
  9.     raise notice 'posle open gavno';
  10. loop   
  11.     raise notice 'loop gavno';
  12.     for r in
  13.     select data.guid, data.name, data.description, data.date_create, data.last_change_date, data.clients_count, data.created_by
  14.         from dblink_fetch('cards_segments', 10000)
  15.         as data (   guid                CHARACTER VARYING(128),
  16.                     name                CHARACTER VARYING(255),
  17.                     last_change_date    TIMESTAMP WITHOUT TIME ZONE,
  18.                     date_create         TIMESTAMP WITHOUT TIME ZONE,
  19.                     clients_count       BIGINT,
  20.                     created_by          CHARACTER VARYING(255),
  21.                     description         TEXT,
  22.                     archive             BOOLEAN)
  23.     loop
  24.         begin
  25.             raise notice 'Insert gavno';
  26.             insert into segments.segments
  27.                 values (r.guid, r.name, r.description, r.date_create, null, r.last_change_date, null, r.clients_count, r.created_by);
  28.         exception
  29.             when unique_violation then
  30.                 raise notice 'Duplicate segment with guid: %, record: %', r.guid, r;
  31.         end;
  32.     end loop;  
  33.     if not found then
  34.         exit;
  35.     end if;
  36. end loop;
  37. perform dblink_close('cards_segments');
  38.  
  39. perform dblink_open('cards_segment_client', 'select * from cards_segment_client');
  40. loop
  41.     for r in
  42.     select data.segment_guid, data.client_guid
  43.     from dblink_fetch('cards_segment_client', 10000)
  44.         as data (   segment_guid    CHARACTER VARYING(128),
  45.                     client_guid     BIGINT)
  46.     loop
  47.         begin
  48.             perform segments.add_client_to_segment(r.client_guid, r.segment_guid);
  49.         exception
  50.             when others then
  51.                 raise notice 'Cannot add client % to segment %', r.client_guid, r.segment_guid;
  52.         end;
  53.     end loop;  
  54.     if not found then
  55.         exit;
  56.     end if;
  57. end loop;
  58. perform dblink_close('cards_segment_client');
  59.  
  60. perform dblink_disconnect();
  61.  
  62. end $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement