Re: problem with copy command

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: Jaruwan Laongmal <jaruwan(at)gits(dot)net(dot)th>, pgsql-sql(at)postgresql(dot)org
Subject: Re: problem with copy command
Date: 2001-04-11 11:59:35
Message-ID: 200104111159.f3BBxa228797@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(dot)Elphick(at)lfix(dot)co(dot)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

Browse pgsql-sql by date

  From Date Subject
Next Message Kovacs Zoltan 2001-04-11 12:02:34 enumerating rows
Previous Message Amanda Riera 2001-04-11 11:31:05 Concatenate fields