Here is a bash program that loads your sample data into a table 'data_locks_keys' and then from that table extracts the 'single' values of column 'key' (with the first associated value of 'source') into a derived table 'data_locks_keys_distinct'.

Takes 1m 30s on 9.5dev postgres (low-end desktop).

#!/bin/sh # wget http://white-barn.com/tmp/data_locks_keys.zip time unzip -p data_locks_keys.zip \ | psql -c " drop table if exists data_locks_keys; create table data_locks_keys(key text, source text); copy data_locks_keys from stdin with ( format csv, delimiter E'|', header FALSE ); " # main table data_locks_keys now has 9,197,129 rows echo " create table data_locks_keys_distinct as select distinct on (key) key, source from data_locks_keys ; " | psql # derived table data_locks_keys_distinct has 3,692,089 rows (with colu +mn 'key' now unique)

I'm really getting curious whether this DISTINCT ON statement isn't what you are looking for...


In reply to Re: Contemplating some set comparison tasks by erix
in thread Contemplating some set comparison tasks by dwhite20899

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.