Re: Overriding default psql behavior | how to ignore missing fields

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Håvard Wahl Kongsgård <haavard(dot)kongsgaard(at)gmail(dot)com>
Subject: Re: Overriding default psql behavior | how to ignore missing fields
Date: 2010-12-31 21:30:40
Message-ID: 201012311330.41091.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gordon Shannon 2010-12-31 21:42:21 Re: seg fault crashed the postmaster
Previous Message Jasen Betts 2010-12-31 21:17:58 Re: Overriding default psql behavior | how to ignore missing fields