Re: create new field - Mailing list pgsql-sql

From Josh Berkus
Subject Re: create new field
Date
Msg-id 200310060944.47636.josh@agliodbs.com
Whole thread Raw
In response to create new field  ("Chris Faulkner" <chrisf@oramap.com>)
List pgsql-sql
Chris,

> template1=# update tab set new_col = "OLD_COL"::int4;
> ERROR:  Cannot cast type character to integer
>
> I understand this - some tables might have characters in the varchar but
> how to get around it in my case ? I know that my character field has only
> integers in it ?

Actually, you just need to use the to_number function as an intermediary:

UPDATE tab SET new_col = CAST(to_number("OLD_COL", '9999') AS INT);

-- 
Josh Berkus
Aglio Database Solutions
San Francisco


pgsql-sql by date:

Previous
From: "Dan Langille"
Date:
Subject: Re: Multiple table join
Next
From: Bruno Wolff III
Date:
Subject: Re: create new field