Re: COPY command

From: Keith Worthington <KeithW(at)NarrowPathInc(dot)com>
To: Mike Nees <jmnees(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: COPY command
Date: 2006-08-16 15:23:00
Message-ID: 44E33854.6020809@NarrowPathInc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

>>>Mike Nees wrote:
>>>
>>>I have several large fixed record length files that I'm trying to load into a new db. My plan is to use a temporary table with one CHAR column to load the file, then use a second staging table to parse the fields and set appropriate data types. When I use the COPY command to load the temporary table I only get part of the record. When I encounter a FILLER column, which appears to be a NULL value, the rest of the record starting with the Filler doesn't load. Total record size is 455, at position 61 is the first filler field, defined as PIC X(1) from the legacy system. I'm able to load all the records in the file into the temporary table, but only for positions 1 through 60. When I looked at the flat file in TextPad, TextPad lists a special character at position 61 with a value as "NUL (^@ = 0 = 0x0)".
>>>
>>>My questions:
>>>
>>>Are these just null characters?
>>>Not knowing PERL; Is there any easy solution to removing these characters programmatically prior to using the COPY command?
>>>
>>>
>>>I can manually remove the NULL characters, but I'm looking for a better solution.
>>>
>>>
>>>Any help would be appreciated.
>>>
>>>Thanks,
>>>
>>>
>>>Mike
>>
>>Mike,
>>
>>The COPY command does allow you to define the NULL character using the
>>WITH NULL AS attribute.
>>
>>COPY mytable
>>FROM 'myfile'
>>WITH NULL AS 'null string';
>>
>>See http://www.postgresql.org/docs/8.0/interactive/sql-copy.html
>>
>>HTH
>>--
>>
>>Kind Regards,
>>Keith
>
> Mike Nees wrote:
> How do I figure out what the "NULL" string would be? The value from TextPad? BTW, I'm running Postgres on XP.
>
>
>
>
> J. Michael Nees
> jmnees(at)hotmail(dot)com

Mike,

The value shown in TextPad might work. If it were me on a Windows box I
would be using gvim to try and determine the same thing.

--

Kind Regards,
Keith

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2006-08-16 15:37:26 Re: libpq Describe Extension [WAS: Bytea and perl]
Previous Message Glenn Davy 2006-08-16 13:46:18 Re: Optimal Postgres Development Process, Software