pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: Jaruwan Laongmal <jaruwan@gits.net.th>
To: pgsql-sql@postgresql.org
Subject: Re: problem with copy command
Date: Wed, 11 Apr 2001 12:59:35 +0100
Message-ID: <200104111159.f3BBxa228797@linda.lfix.co.uk> (raw)
In-Reply-To: <george@dsn.ro> <3AD42379.3FD4F534@dsn.ro>

Here is a method of filtering out the duplicate keys from the input file:

Let us assume that the input data is in /tmp/table.in, that that file is
tab-delimited and that the primary key is in field 2.

    psql -d database -c "COPY table TO '/tmp/table.1'"
    psql -d database -c "COPY table TO '/tmp/table.2'"
    cat /tmp/table.in /tmp/table.[12] |
        sort -k 2 -t \[tab] |
        uniq -u -W 1 -f 1 -t \[tab] >/tmp/table.in.unique

[tab] stands for the sequence "ctrl-V tab", which will force an actual tab
character into the command line (the backslash will protect it from the
shell).

We copy the database out twice to ensure that all keys already in it are
excluded, otherwise we would be reintroducing all primary keys that were
_not_ in the desired input.

The end product is a file that excludes all primary keys that are already
in the target table.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "Is any one of you in trouble? He should pray. Is
      anyone happy? Let him sing songs of praise. Is any one
      of you sick? He should call the elders of the church
      to pray over him...The prayer of a righteous man is
      powerful and effective."         James 5:13,14,16 





view thread (4+ messages)

Message-ID: <200104111159.f3BBxa228797@linda.lfix.co.uk>
Permalink:  ../200104111159.f3BBxa228797@linda.lfix.co.uk/
Also on:    postgresql.org/message-id/200104111159.f3BBxa228797@linda.lfix.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: olly@lfix.co.uk, jaruwan@gits.net.th
  Subject: Re: problem with copy command
  In-Reply-To: <200104111159.f3BBxa228797@linda.lfix.co.uk>
  References: <200104111159.f3BBxa228797@linda.lfix.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox