From: Joel Burton <joel@joelburton.com>
To: Lucas Rockwell <lr@socrates.Berkeley.EDU>
To: pgsql-admin@postgresql.org
Subject: Re: smart copy?
Date: Fri, 26 Apr 2002 17:40:23 -0400
Message-ID: <JGEPJNMCKODMDHGOBKDNAEHCCLAA.joel@joelburton.com> (raw)
In-Reply-To: <Pine.GSO.4.40.0204261250280.10392-100000@socrates.Berkeley.EDU>
If you have a table in database A and want to move it to database B (on the
same or different server):
Drop from your table in Db A ("A.TheTable") all columns that should be
automagically filled in on database B. This would be any nextval() columns,
etc. [It's possible that there aren't present at all in the database A
version, but if they are, get rid of them.]
$ pg_dump --attribute-inserts --data-only --table=TheTable A
Will dump the data from A.TheTable, but rather than as a COPY command, it
will dump it as a series of INSERT commands, in the form:
INSERT INTO TheTable (cola, colb, colc) VALUES (1, 'foo', 'bar');
So that, once you've created the table in database B , you can just pipe
this through psql.
It's slower than running COPY, since you're executing
dozens/hundreds/kajillions of INSERT commands rather than one COPY command.
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.
Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant
> -----Original Message-----
> From: pgsql-admin-owner@postgresql.org
> [mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Lucas Rockwell
> Sent: Friday, April 26, 2002 3:59 PM
> To: pgsql-admin@postgresql.org
> Subject: [ADMIN] smart copy?
>
>
> hi all,
>
> is there a "smart" version of copy that will allow you to copy in data
> when you have a column that is a default nextval(...) but you have no
> data for that column?
>
> basically, i want to import data into a table and the primary
> key value does not exist in my data to import. is this possible?
>
> the "Copy" section of Bruce's book doesn't cover this situation -- unless
> i'm missing something. i skimmed the copy man page and didn't see any
> mention there either.
>
> thanks.
>
> -lucas
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
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-admin@postgresql.org
Cc: joel@joelburton.com, lr@socrates.Berkeley.EDU
Subject: Re: smart copy?
In-Reply-To: <JGEPJNMCKODMDHGOBKDNAEHCCLAA.joel@joelburton.com>
References: <Pine.GSO.4.40.0204261250280.10392-100000@socrates.Berkeley.EDU> <JGEPJNMCKODMDHGOBKDNAEHCCLAA.joel@joelburton.com>
* 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