Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id F143D9FBDA7 for ; Tue, 7 Aug 2007 15:10:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 35524-01 for ; Tue, 7 Aug 2007 15:09:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mx2.ipf.is (jeep.ipf.is [85.197.192.148]) by postgresql.org (Postfix) with ESMTP id 261A99FB7E3 for ; Tue, 7 Aug 2007 15:09:58 -0300 (ADT) Received: (qmail 15780 invoked by uid 1010); 7 Aug 2007 18:09:34 +0000 Received: from 88.149.106.19 by jeep (envelope-from , uid 1008) with qmail-scanner-1.25-st-qms (clamdscan: 0.88.4/1639. spamassassin: 3.1.4. perlscan: 1.25-st-qms. Clear:RC:1(88.149.106.19):SA:0(-2.4/4.5):. Processed in 3.370768 secs); 07 Aug 2007 18:09:34 -0000 X-Antivirus-HIVE-Mail-From: gnari@hive.is via jeep X-Antivirus-HIVE: 1.25-st-qms (Clear:RC:1(88.149.106.19):SA:0(-2.4/4.5):. Processed in 3.370768 secs Process 15761) Received: from dsl-149-106-19.hive.is (HELO ?192.168.1.33?) (88.149.106.19) by mx2.ipf.is with SMTP; 7 Aug 2007 18:09:30 +0000 Subject: Re: Range of caracters From: Ragnar To: Wilton Wonrath Cc: pgsql-sql@postgresql.org In-Reply-To: <603019.54350.qm@web34314.mail.mud.yahoo.com> References: <603019.54350.qm@web34314.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1 Date: Tue, 07 Aug 2007 18:18:14 +0000 Message-Id: <1186510694.5778.401.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/41 X-Sequence-Number: 28979 On ūri, 2007-08-07 at 10:07 -0700, Wilton Wonrath wrote: > Data Table > > Inicial ------------- Final > 9C2HB02107R008000 9C2HB02107R008200 > > FAIXA1 FAIXA100 > > I´m doing the following query: > > SELECT recallfxchassi.* FROM recallfxchassi > LEFT JOIN recall ON recallfxchassi.idrecall = recall.id WHERE > ('FAIXA2' BETWEEN chassiinicial AND chassifinal); > > This is not returning anything. I believe that is because it´s check´s > caracter by caracter and 2 is bigger than 1. But in a real situation > I will need that return something (FAIXA2 is between FAIXA1 and > FAIXA100). > > Does anyone knows if exists some way or command in PostgreSQL that > could solve this "problem" ? sounds like you need to normalize your schema, but it is possible. if the prefix is fixed then you can do WHERE substr('FAIXA2',6)::integer between substr(chassiinicial,6)::integer and substr(chassifinal,6)::integer; if the prefix is not fixed, but it's length is, and you are using a sufficiently recent version of postgresql, you can do: WHERE (substr('FAIXA2',1,5), substr('FAIXA2',6)::integer) between (substr(chassiinicial,1,5), substr(chassiinicial,6)::integer) and (substr(chassifinal,1,5), substr(chassifinal,6)::integer); if the prefix length is not fixed, you will have to do some juggling: WHERE (substring('FAIXA2' from '^[^0-9]*'), substring('FAIXA2' from '[0-9]+$')::integer) between (substr(chassiinicial from '^[^0-9]*'), substr(chassiinicial from '[0-9]+$')::integer) and (substr(chassifinal from '^[^0-9]*'), substr(chassifinal from '[0-9]+$')::integer); gnari