Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do $$
- declare r record;
- begin
- raise notice 'do connect gavno';
- perform dblink_connect('host=9.6.24.188 dbname=set user=postgres password=#Pos324011');
- raise notice 'posle connect gavno';
- perform dblink_open('cards_segments', 'select * from cards_segments limit 5');
- raise notice 'posle open gavno';
- loop
- raise notice 'loop gavno';
- for r in
- select data.guid, data.name, data.description, data.date_create, data.last_change_date, data.clients_count, data.created_by
- from dblink_fetch('cards_segments', 10000)
- as data ( guid CHARACTER VARYING(128),
- name CHARACTER VARYING(255),
- last_change_date TIMESTAMP WITHOUT TIME ZONE,
- date_create TIMESTAMP WITHOUT TIME ZONE,
- clients_count BIGINT,
- created_by CHARACTER VARYING(255),
- description TEXT,
- archive BOOLEAN)
- loop
- begin
- raise notice 'Insert gavno';
- insert into segments.segments
- values (r.guid, r.name, r.description, r.date_create, null, r.last_change_date, null, r.clients_count, r.created_by);
- exception
- when unique_violation then
- raise notice 'Duplicate segment with guid: %, record: %', r.guid, r;
- end;
- end loop;
- if not found then
- exit;
- end if;
- end loop;
- perform dblink_close('cards_segments');
- perform dblink_open('cards_segment_client', 'select * from cards_segment_client');
- loop
- for r in
- select data.segment_guid, data.client_guid
- from dblink_fetch('cards_segment_client', 10000)
- as data ( segment_guid CHARACTER VARYING(128),
- client_guid BIGINT)
- loop
- begin
- perform segments.add_client_to_segment(r.client_guid, r.segment_guid);
- exception
- when others then
- raise notice 'Cannot add client % to segment %', r.client_guid, r.segment_guid;
- end;
- end loop;
- if not found then
- exit;
- end if;
- end loop;
- perform dblink_close('cards_segment_client');
- perform dblink_disconnect();
- end $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement