Re: Finding bogus dates

From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: Scott Ribe <scott_ribe(at)killerbytes(dot)com>
Cc: "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Finding bogus dates
Date: 2007-01-18 19:06:10
Message-ID: 45AFC522.7010803@fuzzy.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Suppose that I have a varchar column which contains dates, and some of them
> are bogus, such as '1968-02-31'. Is it possible to specify a query condition
> "cannot be cast to a valid date". (It's legacy data, and I'm trying to clean
> it up before importing into the final schema.) There probably aren't that
> many, and I can just keep hitting pg errors one row at a time until I work
> through this, but...

I guess you can use something like this procedure:

create or replace function is_date(d varchar) returns boolean as $$
declare
tmp date;
begin
tmp := d::date;
return true;
exception
when others then
return false;
end;
$$ language plpgsql;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Ribe 2007-01-18 19:21:28 Re: Finding bogus dates
Previous Message Adam Rich 2007-01-18 18:52:13 Re: Finding bogus dates