D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Importing CSV files into postgres



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Roland Tarver wrote:
> I only need something very simple, can I import from csv in psql using
> some sql statements?

I don't think so, not without manipulating the data into a format the
Postgres "copy" command can handle.

Plenty of scripts and tools out there.

> i only need to do this once.

For the effort in manipulating such data into an acceptable form you may
just as easily be able to use "vi" to change each line into valid SQL
insert.

Syntax is

insert into tablename (col1, col2, col3) values ( value1, value2 .... );

So basically you need to tack a little text on beginning and end, if the
csv is clean enough.
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+v3KmGFXfHI9FVgYRAmAmAJ4t01lvg/THv8rKpLsQif9OGr9RngCgte5m
D8OwA7h/GKbWGz43Th5fDCw=
=WpKO
-----END PGP SIGNATURE-----

--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly