Re: Date format for bulk copy - Mailing list pgsql-general

From Greg Stark
Subject Re: Date format for bulk copy
Date
Msg-id 87acuq5z2e.fsf@stark.xeocode.com
Whole thread Raw
In response to Date format for bulk copy  (David Rysdam <drysdam@ll.mit.edu>)
Responses Re: Date format for bulk copy  (David Rysdam <drysdam@ll.mit.edu>)
List pgsql-general
David Rysdam <drysdam@ll.mit.edu> writes:

> In my brute force port, I just bulk copied the date
> fields into temporary tables and then did a to_timestamp(field, 'Mon DD YYYY
> HH:MI:SS:MSAM').

> Again, I created a temporary table and did a decode(field, 'hex') to the
> real table.

This is the standard approach. You're rather lucky these are the only
data representation changes you've had to do so far. I fear you'll run into
more and more complex changes over time and trying to avoid the temporary
table will get harder and harder.

If it were me I would consider processing the files in perl. It should be
pretty easy to do both of these modifications very quickly.


If you really want to go with a custom C code then you might be able to just
grab the byteain/byteaout functions from src/backend/util/adt/varlena into a
separate module and create new functions with modified names. Load it with
CREATE FUNCTION byteain ... AS 'my_bytea_funcs.so' 'my_byteain';

Or maybe create the function as my_byteain in postgres and then update the
catalog entries somehow. I'm not sure how to do that but it shouldn't be too
hard. And it might make it easier to do the substitution for the data load and
then undo the change afterwards.

Doing the same for timmestamp is a bit trickier but you could copy
ParseDateTime from datetime.c as a static function for your module.

Be careful though, test this out thoroughly on a test database. I'm not sure
of all the impacts of altering the in/out functions for data types. I expect
it would break pg_dump, for example. And I would worry about the statistics
tables too.

--
greg

pgsql-general by date:

Previous
From: Steve Wolfe
Date:
Subject: Still more pg_clog errors
Next
From: Robby Russell
Date:
Subject: Re: ODBC