Re: More PostgreSQL conversion fun

From: "Guy Rouillier" <guyr(at)masergy(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: More PostgreSQL conversion fun
Date: 2006-04-09 01:27:01
Message-ID: CC1CF380F4D70844B01D45982E671B230137A85C@mtxexch01.add0.masergy.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nick Wiltshire wrote:
> Hi all,
>
> I have a varchar field in a table which contains dates in yyyy-mm-dd
> format. The problem is that some have entered invalid dates like
> 1975-01-00 and I want to convert it to a date field to avoid this
> nonsense. Is there a way to test for failure of a type conversion and
> insert a NULL on failure?
>

Not the question you asked, but perhaps a suitable alternative: before
attempting to convert, scan all the rows in the table looking for any
contents of that column not fitting the format yyyy-mm-dd. Then you can
either fix them or null them out.

--
Guy Rouillier

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Frost 2006-04-09 02:03:03 Re: Debian package for freeradius_postgresql module
Previous Message Chris Travers 2006-04-09 00:29:03 Re: Debian package for freeradius_postgresql module