pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kretschmer Andreas <andreas_kretschmer@despammed.com>
To: pgsql-sql@postgresql.org
Subject: Re: [despammed] converting varchar to integer
Date: Wed, 17 Aug 2005 11:30:29 +0200
Message-ID: <20050817093029.GA1647@kaufbach.delug.de> (raw)
In-Reply-To: <1124235288.43027818cb6e3@email.gigaweb.cz>
References: <1124235288.43027818cb6e3@email.gigaweb.cz>

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° ;-)



view thread (7+ messages)  latest in thread

Message-ID: <20050817093029.GA1647@kaufbach.delug.de>
Permalink:  ../20050817093029.GA1647@kaufbach.delug.de/
Also on:    postgresql.org/message-id/20050817093029.GA1647@kaufbach.delug.de

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreas_kretschmer@despammed.com
  Subject: Re: [despammed] converting varchar to integer
  In-Reply-To: <20050817093029.GA1647@kaufbach.delug.de>

* 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