Home > Archive > PostgreSQL SQL > August 2005 > Re: [despammed] converting varchar to integer









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [despammed] converting varchar to integer
Kretschmer Andreas

2005-08-17, 9:30 am

tv@fuzzy.cz <tv@fuzzy.cz> schrieb:

> Hi,
>
> I have a varchar column, and I need to
>
> 1) check the value in it is an integer
> 2) get the integer value (as integer)
>
> The problem is I can't suppose the're only correct
> values - ie there can be something like 'xssdkjsd',
> '230kdd' or even an empty string etc.


test=# select * from foo;
t | n
------+---
bla |
bla1 |
2 |
(3 rows)

test=# update foo set n = substring(t , '[0-9]')::int;
UPDATE 3
test=# select * from foo;
t | n
------+---
bla |
bla1 | 1
2 | 2
(3 rows)


Regards, Andreas
--
Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau-
fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei
von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA
Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com