Re: COPY command

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: azwa(at)nc(dot)com(dot)my
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: COPY command
Date: 2004-01-09 04:49:45
Message-ID: 3EE27553-425F-11D8-9330-000A95C88220@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Jan 9, 2004, at 1:11 PM, azwa(at)nc(dot)com(dot)my wrote:
> how do we run the COPY command from file which has several null
> columns in each field.  
> thanks.
>
> example :
>
>    dwnc=# copy biosadm.custinv_temp
> dwnc-# from '/home/bios/customer_data/CustomerInvoice_5Dec03_tab.txt' ;
> ERROR:  copy: line 1, Missing data for column "subsidiary"  

Just like you specify the delimiter, you need to specify the value for
NULL. For example, if your *.txt file has a line with a "missing" value
(such as the space between 'bar' and 'foofoo')

foo bar foofoo barbar

I usually use 'NULL' as NULL, so the line would be

foo bar NULL foofoo barbar

then use the COPY command with NULL AS 'NULL'

Check out the following link for detailed info on the COPY command:
<http://www.postgresql.org/docs/current/static/sql-copy.html>

HTH

Michael Glaesemann
grzm myrealbox com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Creager 2004-01-09 04:59:58 Re: grouping by date
Previous Message azwa 2004-01-09 04:11:29 Re: COPY command