Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4900E632FFD for ; Fri, 4 Sep 2009 23:37:58 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 79593-04 for ; Sat, 5 Sep 2009 02:37:49 +0000 (UTC) X-Greylist: delayed 00:05:22.63805 by SQLgrey-1.7.6 Received: from images.kandalaya.org (etc.kandalaya.org [83.143.86.98]) by mail.postgresql.org (Postfix) with ESMTP id CE384632AC7 for ; Fri, 4 Sep 2009 23:37:49 -0300 (ADT) Received: from mail.linux-delhi.org (ABTS-North-Dynamic-115.220.163.122.airtelbroadband.in [122.163.220.115] (may be forged)) by images.kandalaya.org (8.14.3/8.14.3/Debian-9) with ESMTP id n852WJad014038 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 5 Sep 2009 08:02:22 +0530 Received: from mail.linux-delhi.org (localhost [127.0.0.1]) by mail.linux-delhi.org (8.14.3/8.14.3/Debian-9) with ESMTP id n852WAOD022787 for ; Sat, 5 Sep 2009 08:02:11 +0530 From: Raj Mathur Reply-To: raju@linux-delhi.org Organization: Kandalaya To: pgsql-sql@postgresql.org Subject: Re: Substring Date: Sat, 5 Sep 2009 08:02:09 +0530 User-Agent: KMail/1.11.4 (Linux/2.6.30-1-686; KDE/4.2.4; i686; ; ) References: <15318.85292.qm@web53905.mail.re2.yahoo.com> In-Reply-To: <15318.85292.qm@web53905.mail.re2.yahoo.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200909050802.10371.raju@linux-delhi.org> X-Virus-Scanned: clamav-milter 0.95.2 at images.kandalaya.org X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.297 tagged_above=-10 required=5 tests=BAYES_40=-0.185, DNS_FROM_RFC_BOGUSMX=1.482 X-Spam-Level: * X-Archive-Number: 200909/26 X-Sequence-Number: 33091 On Saturday 05 Sep 2009, bilal ghayyad wrote: > I have an sql script function that take one text parameter "funct > (text)", what I need to do is the following: > > If the parameter name is string and its value was for example "abcd" > then I need to do a query based on ab and then based on the abc, how? > > Example: > > SELECT * from voipdb where prefix like string > > But I need the string to be ab and then to be abc? How I can assign > the string to the first character and then to the first and second? > In other words, how can I can take part of the string to do query on > it? =46rom your example the following brute-force method should work (not=20 tested): select * from voipdb where prefix like substring(string from 1 for 2) ||=20 '%' or prefix like substring(string from 1 for 3) || '%'; However, I don't understand why you'd want to search for both 'ab' and=20 'abc' in the same query, since the first condition is a superset of the=20 second one. Regards, =2D- Raju =2D-=20 Raj Mathur raju@kandalaya.org http://kandalaya.org/ GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F PsyTrance & Chill: http://schizoid.in/ || It is the mind that moves