From: Hogan, James F. Jr. <JHogan@seton.org>
To: Jorge Godoy <jgodoy@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Returning String as Integer
Date: Fri, 5 May 2006 16:58:03 -0500
Message-ID: <D73D467FE58F004E9D3FA25414945DC104FE0E1C@AUSEX3VS1.seton.org> (raw)
Here is a Perl function a friend of mine wrote to help with this...
Problems I ran into were errors because of NON NUMERIC Characters in the
String...
Casting would fail
It doesn't catch all cases but it has been quite helpful to me
$x = $_[0];
$x =~ s/^[^-\d\.]*//;
$x =~ s/\,//g;
$x = $x * 1;
return $x;
-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Jorge Godoy
Sent: Friday, May 05, 2006 4:52 PM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] Returning String as Integer
Em Sexta 05 Maio 2006 18:37, Kashmira Patel (kupatel) escreveu:
> Hi all,
> I have a table with a column of type 'text'. It mainly contains
> numbers. Is there any way to select a value from this column and
return
> it as an integer?
testing=# select '123'::integer;
int4
------
123
(1 registro)
testing=#
--
Jorge Godoy <jgodoy@gmail.com>
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: JHogan@seton.org, jgodoy@gmail.com
Subject: Re: Returning String as Integer
In-Reply-To: <D73D467FE58F004E9D3FA25414945DC104FE0E1C@AUSEX3VS1.seton.org>
References: <D73D467FE58F004E9D3FA25414945DC104FE0E1C@AUSEX3VS1.seton.org>
* 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