From: | "Hogan, James F(dot) Jr(dot)" <JHogan(at)seton(dot)org> |
---|---|
To: | "Jorge Godoy" <jgodoy(at)gmail(dot)com> |
Cc: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Returning String as Integer |
Date: | 2006-05-05 21:58:03 |
Message-ID: | D73D467FE58F004E9D3FA25414945DC104FE0E1C@AUSEX3VS1.seton.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)postgresql(dot)org
[mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Jorge Godoy
Sent: Friday, May 05, 2006 4:52 PM
To: pgsql-sql(at)postgresql(dot)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(at)gmail(dot)com>
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
From | Date | Subject | |
---|---|---|---|
Next Message | Kashmira Patel (kupatel) | 2006-05-05 22:04:58 | Re: Returning String as Integer |
Previous Message | Jorge Godoy | 2006-05-05 21:52:19 | Re: Returning String as Integer |