Re: [despammed] converting varchar to integer

From: Kretschmer Andreas <andreas_kretschmer(at)despammed(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [despammed] converting varchar to integer
Date: 2005-08-17 09:30:29
Message-ID: 20050817093029.GA1647@kaufbach.delug.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

tv(at)fuzzy(dot)cz <tv(at)fuzzy(dot)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° ;-)

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Halley Pacheco de Oliveira 2005-08-17 10:46:05 Re: converting varchar to integer
Previous Message Lee Hyun soon 2005-08-17 05:29:45 pgsql-bugs