Re: CSV files & empty strings - Mailing list pgsql-general

From Niklas Johansson
Subject Re: CSV files & empty strings
Date
Msg-id 25C480FD-49F1-4BEF-BC5E-53764F03C327@codecraft.se
Whole thread Raw
In response to Re: CSV files & empty strings  (Raymond O'Donnell <rod@iol.ie>)
List pgsql-general
On 20 okt 2009, at 16.15, Raymond O'Donnell wrote:

> On 20/10/2009 05:55, Nate Randall wrote:
>> However, I need some method of "converting" the
>> empty string "" values into NULL values after import, so that I can
>> change the date fields back to date-type.  Any suggestions on how
>> this
>> could be accomplished?
>
> How about:
>
>   update <table> set <column> = null where <column> = '';


You can also do the update and the column data type change in one
fell swoop like so:

ALTER TABLE table_name ALTER COLUMN column_name
SET DATA TYPE DATE USING NULLIF(column_name, '')::DATE;




Sincerely,

Niklas Johansson




pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: [ANNOUNCE] [pgeu-general] PGDay.EU 2009 - approaching fast!
Next
From: Tim Landscheidt
Date:
Subject: Re: How to list user-specific configuration parameters?