X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 573FC9FA5B5 for ; Mon, 11 Sep 2006 20:51:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 26495-07 for ; Mon, 11 Sep 2006 23:50:52 +0000 (UTC) X-Greylist: delayed 00:16:08.756133 by SQLgrey- Received: from viefep17-int.chello.at (viefep13-int.chello.at [213.46.255.16]) by postgresql.org (Postfix) with ESMTP id EEE099F9F7F for ; Mon, 11 Sep 2006 20:50:51 -0300 (ADT) Received: from [192.168.7.3] (really [89.173.26.202]) by viefep16-int.chello.at (InterMail vM.6.01.04.04 201-2131-118-104-20050224) with ESMTP id <20060911233439.ZVPU21606.viefep16-int.chello.at@[192.168.7.3]> for ; Tue, 12 Sep 2006 01:34:39 +0200 Message-ID: <4505F28E.6060606@nekomancer.net> Date: Tue, 12 Sep 2006 01:34:38 +0200 From: gabor User-Agent: Thunderbird 1.5.0.5 (Macintosh/20060719) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: text+number, find largest entry Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200609/73 X-Sequence-Number: 26284 hi, i have a table, where there is a varchar(500) column, which contains data that is strangely formatted: it starts with letters, and ends with a number. for example: xyz001 xyz002 xyz044 xyz1243 abc01 abc993 abc2342 and so on. now, for a given text-prefix (for example "xyz"), i need to find the record with the largest "numeric component". so for example, for the text-prefix "xyz", the corresponding entry would be "xyz1243". this lookup does not have to be especially fast. i realize that i could add some additional columns to this table, and store the text-part and the numeric-part separately, but first i would prefer a non-alter-table solution :) currently my only idea is to find the longest entry, check how many of them are, and then find the ones whose numeric part starts with "9" etc... ugly, but should work. are there any better ways to do it? thanks, gabor