Re: copy in date string "00-00-00 00:00:00"

From: Martin Gregorie <martin(at)gregorie(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: copy in date string "00-00-00 00:00:00"
Date: 2012-03-15 08:24:59
Message-ID: 1331799899.15175.142.camel@zappa.gregorie.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Goess 2012-03-15 09:47:03 WHERE IN (subselect) versus WHERE IN (1,2,3,)
Previous Message Alexander Reichstadt 2012-03-15 07:47:11 Re: pg_role vs. pg_shadow or pg_user