Re: create new field

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "Chris Faulkner" <chrisf(at)oramap(dot)com>, "Pgsql-Sql" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: create new field
Date: 2003-10-06 16:44:47
Message-ID: 200310060944.47636.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2003-10-06 16:56:09 Re: create new field
Previous Message Dan Langille 2003-10-06 16:39:43 Re: Multiple table join