Re: Change column type to numeric

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jake Franklin <jfranklin(at)denvergeek(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Change column type to numeric
Date: 2008-02-10 18:52:56
Message-ID: 20080210185255.GA43421@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Feb 10, 2008 at 11:37:45AM -0700, Jake Franklin wrote:
> test=# alter table foo alter column amount type numeric(10,2) USING
> cast(amount AS numeric);
> ERROR: invalid input syntax for type numeric: ""
>
> I'm assuming that it's trying to cast a blank value as numeric and
> failing. Does anyone know of an easy way to work around this?

You could convert the empty strings to NULL:

USING cast(nullif(amount, '') AS numeric)

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erik Jones 2008-02-10 18:55:20 Re: Is PG a moving target?
Previous Message Jake Franklin 2008-02-10 18:37:45 Change column type to numeric