Re: [GENERAL] one problem

From: Stuart Rison <stuart(at)ludwig(dot)ucl(dot)ac(dot)uk>
To: Jonathan davis <haj(at)idianet(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] one problem
Date: 1999-07-06 12:43:37
Message-ID: v04020a01b3a7a80a5e25@[128.40.242.190]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>Hello all
>>
>>how to get back one database (text format) to postgresql ?
>>
>>field1 field2 field3 ...
>>field1 field2 field3 ...
>>.
>>.
>>.
>>
>>thanks
>>
>
>
>the COPY command does that BUT BUT BUT BUT !!!
>how to specify the fields for example I just insert field2 into the
>database
>
>example:
>
>create table country (code char(2), country char(20));
>
>and i want to insert just the field country not the field code
>
>how to proceed ?

Salut Jonathan,

Hum... don't think you could do that with a COPY in one step

you could COPY all of that data into a temp table and then INSERT the
fields you want into the final table and delete the old ones so:

(in psql)

CREATE TABLE temp_copy (field1 text, field2 text, field3 text); --
obviously, use the right types

COPY temp_copy FROM <text_format_database>;

INSERT INTO country (country) SELECT field2 FROM temp_copy; -- or whatever
field or fields you want,

-- you could also use SELECT INTO command to create TABLE country on the
fly and alter it with ALTER TABLE if necessary.

DROP TABLE temp_copy;

HTH,

Stuart.

+-------------------------+--------------------------------------+
| Stuart Rison | Ludwig Institute for Cancer Research |
+-------------------------+ 91 Riding House Street |
| Tel. (0171) 878 4041 | London, W1P 8BT, UNITED KINGDOM. |
| Fax. (0171) 878 4040 | stuart(at)ludwig(dot)ucl(dot)ac(dot)uk |
+-------------------------+--------------------------------------+

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stuart Rison 1999-07-06 12:52:12 Re: [GENERAL] Stuck in a vacuum.
Previous Message Jonathan davis 1999-07-06 12:22:21 Re: [GENERAL] one problem