Re: copy in date string "00-00-00 00:00:00" - Mailing list pgsql-general

From Martin Gregorie
Subject Re: copy in date string "00-00-00 00:00:00"
Date
Msg-id 1331799899.15175.142.camel@zappa.gregorie.org
Whole thread Raw
In response to Re: copy in date string "00-00-00 00:00:00"  (Mark Phillips <Mark.Phillips@mophilly.com>)
List pgsql-general
On Wed, 2012-03-14 at 21:52 -0700, Mark Phillips wrote:
> I am not familiar with sed, except for some trivial bits I nicked off
> the web. Enough to know it works, and to be dangerous. Nonetheless,
> using SED may be the way to go as there are two tables that contain a
> bit over 3,000,000 rows each.
>
You should also consider using awk/gawk with the field separator (FS
variable) set to match the one in your input (','). The advantages in
this case are that it can be made to work on specific fields in the CSV
file and not look at the rest, something like:

BEGIN { FS = ','; }                      # set field sep to comma
$5 == '0000-00-00 00:00:00' { $5 = '' }  # empty field 5 if it matches
                            {print }     # output all lines

Disclaimer: this is untested example code


Martin






pgsql-general by date:

Previous
From: Alexander Reichstadt
Date:
Subject: Re: pg_role vs. pg_shadow or pg_user
Next
From: Richard Harley
Date:
Subject: Backups