From: Josh Berkus <josh@agliodbs.com>
To: Chris Faulkner <chrisf@oramap.com>
To: Pgsql-Sql <pgsql-sql@postgresql.org>
Subject: Re: create new field
Date: Mon, 6 Oct 2003 09:44:47 -0700
Message-ID: <200310060944.47636.josh@agliodbs.com> (raw)
In-Reply-To: <DGENKIKMJILAAKJGFHKFAEHPCIAA.chrisf@oramap.com>
References: <DGENKIKMJILAAKJGFHKFAEHPCIAA.chrisf@oramap.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, chrisf@oramap.com
Subject: Re: create new field
In-Reply-To: <200310060944.47636.josh@agliodbs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox