Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWsZV-0005cB-PB for pgsql-sql@arkaria.postgresql.org; Thu, 17 Oct 2013 18:45:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VWsZV-0007Ou-3l for pgsql-sql@arkaria.postgresql.org; Thu, 17 Oct 2013 18:45:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWsZU-0007On-4s for pgsql-sql@postgresql.org; Thu, 17 Oct 2013 18:45:20 +0000 Received: from mbx.knossos.net.nz ([202.160.48.10]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWsZO-0003qp-T5 for pgsql-sql@postgresql.org; Thu, 17 Oct 2013 18:45:19 +0000 Received: from [10.1.1.3] (60-234-150-59.bitstream.orcon.net.nz [60.234.150.59]) (authenticated bits=0) by mbx.knossos.net.nz (8.14.4/8.14.4) with ESMTP id r9HIj11a000399 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 18 Oct 2013 07:45:02 +1300 Message-ID: <52602FBA.50303@archidevsys.co.nz> Date: Fri, 18 Oct 2013 07:43:06 +1300 From: Gavin Flower Organization: ArchiDevSys User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: Alvaro Herrera , Gary Stainburn CC: "pgsql-sql@postgresql.org" Subject: Re: Advice - indexing on varchar fields where only last x characters known References: <201310171220.44550.gary.stainburn@ringways.co.uk> <20131017183902.GA4943@eldon.alvh.no-ip.org> In-Reply-To: <20131017183902.GA4943@eldon.alvh.no-ip.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 18/10/13 07:39, Alvaro Herrera wrote: > Gary Stainburn wrote: > >> The problem that I have is that these VIN numbers are provided by a number of >> data systems including manufacturer feeds, logistics companies as well as >> internal systems. Some use the full 17 character string while others only use >> the last 11. >> >> On top of this, my users are used to only having to type the last 6 characters >> for speed and usability reasons. > Try creating an index on reverse(vin) and using the same function in > queries; you can put a % at the end of the sought-for literal to match > suffixes. That works quite well and is very simple to implement. > That is extremely cunning, and obvious in retrospect! :-) Cheers, Gavin -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql