Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id A39DE474E4E for ; Fri, 26 Apr 2002 18:50:48 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g3QMohF12694; Fri, 26 Apr 2002 18:50:43 -0400 (EDT) To: "Joel Burton" Cc: "Lucas Rockwell" , pgsql-admin@postgresql.org Subject: Re: smart copy? In-reply-to: References: Comments: In-reply-to "Joel Burton" message dated "Fri, 26 Apr 2002 17:40:23 -0400" Date: Fri, 26 Apr 2002 18:50:42 -0400 Message-ID: <12691.1019861442@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200204/270 X-Sequence-Number: 4158 "Joel Burton" writes: > $ pg_dump --attribute-inserts --data-only --table=TheTable A > > It's slower than running COPY, since you're executing > dozens/hundreds/kajillions of INSERT commands rather than one COPY command. Yup, lots slower. A better idea (which also doesn't require redoing the export) is: 1. Create a temp table that matches the columns present in your data file. 2. COPY from data file into temp table. 3. INSERT INTO target_table (column list) SELECT * FROM temp_table; You can do pretty much any transformation you need to in the INSERT/SELECT, so this generalizes to a lot of related cases where your data file doesn't quite match the data layout you want. > If that's a problem, you can reduce it a bit by dropping indexes and > triggers on B.TheTable, doing the INSERTs, then re-adding these. For a big import that will still be a good idea --- drop the indexes and recreate after you've imported. As for triggers, that depends on whether you need whatever they'd do ... regards, tom lane