pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tim Pizey <tim@paneris.co.uk>
Cc: pgsql-sql@postgresql.org
Cc: bloomsbury_development@messageboards.paneris.org
Subject: Re: [SQL] Newbie dbadmin out of his league
Date: Fri, 27 Aug 1999 17:19:18 -0400
Message-ID: <7648.935788758@sss.pgh.pa.us> (raw)
In-Reply-To: <3.0.3.32.19990827211232.006f4c40@popmail.dircon.co.uk>

Tim Pizey <tim@paneris.co.uk> writes:
> 2. How do I use COPY?

>    Presumably I again have to take control of the key values,
>    drop the index
>    copy from tab delimited file containing hard ids
>    create id sequence
>    create index
>    modify id definition

Yup, that's about what you need to do.  You can leave the "DEFAULT"
clause where it is, since it won't be invoked during a COPY that's
supplying non-default values for the ID column.  (A good thing too,
since I don't think we support ALTER TABLE ADD DEFAULT...)

Just create the sequence with the right starting value (one past last
ID being loaded).  You can do that before or after the COPY, doesn't
matter.

A COPY will be way faster than a series of INSERT commands, especially
if each INSERT is invoking a nextval().  nextval() is great for
serializing live updates but it's pretty inefficient for a bulk-loading
situation.  Creating the index after the load is reputed to be faster
than building it incrementally, as well.

BTW, I believe pg_dump gets this right, so you could look at the script
generated by pg_dump of a small sample table for details.

			regards, tom lane



view thread (6+ messages)  latest in thread

Message-ID: <7648.935788758@sss.pgh.pa.us>
Permalink:  ../7648.935788758@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/7648.935788758@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, tim@paneris.co.uk, bloomsbury_development@messageboards.paneris.org
  Subject: Re: [SQL] Newbie dbadmin out of his league
  In-Reply-To: <7648.935788758@sss.pgh.pa.us>
  References: <3.0.3.32.19990827211232.006f4c40@popmail.dircon.co.uk> <7648.935788758@sss.pgh.pa.us>

* 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