one problem

Started by Jonathan davisalmost 27 years ago4 messagesgeneral
Jump to latest
#1Jonathan davis
haj@idianet.net

Hello all

how to get back one database (text format) to postgresql ?

field1 field2 field3 ...
field1 field2 field3 ...
.
.
.

thanks

#2Jonathan davis
haj@idianet.net
In reply to: Jonathan davis (#1)
Re: [GENERAL] one problem

-----Message d'origine-----
De : Jonathan davis <haj@idianet.net>
� : 'pgsql-general@postgreslq.org' <pgsql-general@postgreSQL.org>
Date : mardi 6 juillet 1999 12:45
Objet : [GENERAL] one problem

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 ?

#3Stuart Rison
stuart@ludwig.ucl.ac.uk
In reply to: Jonathan davis (#2)
Re: [GENERAL] one problem

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@ludwig.ucl.ac.uk              |
+-------------------------+--------------------------------------+
#4Peter Eisentraut
peter_e@gmx.net
In reply to: Jonathan davis (#2)
Re: [GENERAL] one problem

On Tue, 6 Jul 1999, Jonathan davis wrote:

-----Message d'origine-----
De : Jonathan davis <haj@idianet.net>
� : 'pgsql-general@postgreslq.org' <pgsql-general@postgreSQL.org>
Date : mardi 6 juillet 1999 12:45
Objet : [GENERAL] one problem

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 ?

Some bash or perl magic to preprocess that file could help. I hear the
cut(1) command does wonders.

--
Peter Eisentraut
PathWay Computing, Inc.