Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: Extract onl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 15467 of 16941
Post > Topic >>

Re: Extract only numbers from a varchar column

by bopolissimus.lists@[EMAIL PROTECTED] (Gerald Quimpo) May 10, 2008 at 08:54 PM

On Tuesday 06 May 2008 07:09:56 Leandro Casadei wrote:
> I need to extract only the first occurence of numbers from a column 
that
> is varchar.
<snip>
> abc200xx -> 200
> 340ppsdd -> 340
> 150ytyty555 -> 150

tiger=> select substring('abc200xx300ff','[0-9]+');
 substring 
-----------
 200
(1 row)

Time: 0.495 ms
tiger=> select substring('340ppsdd','[0-9]+');
 substring 
-----------
 340
(1 row)

Time: 0.480 ms
tiger=> select substring('150ytyty555','[0-9]+');
 substring 
-----------
 150
(1 row)

Time: 0.494 ms

tested on 8.2.  i don't have 8.3 here, so i don't know if there will
be type coercion issues there.  doubt it though.

tiger

-- 
Gerald Timothy Quimpo   bopolissimus@[EMAIL PROTECTED]
  If you don't know who Knuth is, then you're not a programmer. If
   you're a programmer and you don't know who Knuth is, well... you
   should probably be fired.
-- scienceblogs.com/goodmath/2008/01/the_genius_of_donald_knuth_typ.php

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 3 Posts in Topic:
Extract only numbers from a varchar column
mateamargo@[EMAIL PROTECT  2008-05-05 14:08:55 
Re: Extract only numbers from a varchar column
mateamargo@[EMAIL PROTECT  2008-05-05 16:09:56 
Re: Extract only numbers from a varchar column
bopolissimus.lists@[EMAIL  2008-05-10 20:54:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 12:35:45 CDT 2008.