X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8C59152971 for ; Wed, 17 Aug 2005 06:27:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20049-03 for ; Wed, 17 Aug 2005 09:27:30 +0000 (GMT) Received: from 137086.vserver.de (vs137086.vserver.de [62.75.137.86]) by svr1.postgresql.org (Postfix) with ESMTP id C7BCE529EE for ; Wed, 17 Aug 2005 06:27:28 -0300 (ADT) Received: from a-kretschmer.de (p54B398B9.dip0.t-ipconnect.de [84.179.152.185]) (authenticated bits=0) by 137086.vserver.de (8.12.8/8.12.8) with ESMTP id j7H9RRTU030337 for ; Wed, 17 Aug 2005 11:27:28 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 3.36 #1) id 1E5KFi-0000WV-00 for pgsql-sql@postgresql.org; Wed, 17 Aug 2005 11:30:30 +0200 Date: Wed, 17 Aug 2005 11:30:29 +0200 From: Kretschmer Andreas To: pgsql-sql@postgresql.org Subject: Re: [despammed] converting varchar to integer Message-ID: <20050817093029.GA1647@kaufbach.delug.de> References: <1124235288.43027818cb6e3@email.gigaweb.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1124235288.43027818cb6e3@email.gigaweb.cz> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: mutt-ng 1.5.9i (Linux) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.082 required=5 tests=[AWL=0.032, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/120 X-Sequence-Number: 22348 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° ;-)