Skip to content

Instantly share code, notes, and snippets.

@vinnix
Created November 12, 2010 14:21
Show Gist options
  • Select an option

  • Save vinnix/257f544bf1380ef546ed to your computer and use it in GitHub Desktop.

Select an option

Save vinnix/257f544bf1380ef546ed to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION proc_split_contacts() RETURNS TABLE(quantity int, total int, x_time numeric) as $body$
DECLARE
i INTEGER;
s INTEGER;
v_time numeric;
curs1_tosplit CURSOR FOR
SELECT id, generation, vcard, created_by, user_id, parents, deleted,
CASE WHEN deleted = true THEN COALESCE(deleted_at, updated_at) ELSE updated_at END
FROM contacts WHERE in_transit = false LIMIT 500;
BEGIN
SELECT (EXTRACT(minute FROM current_timestamp) * 60) + EXTRACT(second FROM current_timestamp) into v_time;
FOR rowvar IN curs1_tosplit
LOOP
RAISE NOTICE 'Contact.id(%)', rowvar.id;
i := i +1;
--
--
-- get logic on gist
END LOOP;
SELECT ((EXTRACT(minute FROM current_timestamp) * 60) + EXTRACT(second FROM current_timestamp)) - v_time into v_time;
RETURN QUERY SELECT i, s,v_time ;
END;
$body$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment