Re: Overriding default psql behavior | how to ignore missing fields - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Overriding default psql behavior | how to ignore missing fields
Date
Msg-id 201012311330.41091.adrian.klaver@gmail.com
Whole thread Raw
In response to Overriding default psql behavior | how to ignore missing fields  (Håvard Wahl Kongsgård <haavard.kongsgaard@gmail.com>)
List pgsql-general
On Friday 31 December 2010 9:06:19 am Håvard Wahl Kongsgård wrote:
> Well I created the SQL files from multiple shapefiles. Used the shp2sql (
> postgis 1.5) to generate the SQL dumps.
>

And the shp2pgsql docs say:

"Appends data from the Shape file into the database table. Note that to use this
option to load multiple files, the files must have the same attributes and same
data types. "

The problem is just not adding/removing the field(s) from the target table but
also maintaining field order. The inserts are assuming a set order and number
of fields. My guess is the answer lies in using the -c option to shp2pgsql and
have it create the tables for each file in the database. You could then move
the fields you need to the target table. Another route would be to use the -D
option which creates a Postgres dump format for the data i.e COPY see below for
example:

COPY table2 (fulldate, id, meanvalue) FROM stdin;
2009-01-01 00:00:00 1 12.3
2009-01-01 01:00:00 1 11.8
2009-01-01 02:00:00 1 82.099998
2009-01-01 03:00:00 1 79.800003
2009-01-01 04:00:00 1 77.199997
2009-01-01 05:00:00 1 13.1

You could probably use that and a script to feed the data to your target.



--
Adrian Klaver
adrian.klaver@gmail.com

pgsql-general by date:

Previous
From: Jasen Betts
Date:
Subject: Re: Overriding default psql behavior | how to ignore missing fields
Next
From: Gordon Shannon
Date:
Subject: Re: seg fault crashed the postmaster