Re: selecting for type cast failures - Mailing list pgsql-general

From Guy Rouillier
Subject Re: selecting for type cast failures
Date
Msg-id 51395C18.4000208@gmail.com
Whole thread Raw
In response to selecting for type cast failures  (Natalie Wenz <nataliewenz@ebureau.com>)
List pgsql-general
On 3/7/2013 8:08 PM, Natalie Wenz wrote:
> I am working on updating some of our tables to use appropriate native
> data types;  they were all defined as text when they were created
> years ago.
>
> What I am running into, though, is there are some records that have
> bad data in them, where they can't be successfully converted to int,
> or float, or boolean, for example.
>
> Is there a straightforward way to identify offending records?
>
> I've been able to identify some with things like "...not similar to
> '(0|1)'..." for the boolean fields, and "...not similar to
> '[0-9]{1,}'..." for int. Are regular expressions the best approach
> here or is there a better way?

I did some quick searching also, looks like regular expressions are your
way to go.  Here is one for isInteger, for example:

    varchar ~ '^[0-9]+$'

--
Guy Rouillier


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Making planner skip hard-coded view values?
Next
From: Adrian Klaver
Date:
Subject: Re: selecting for type cast failures