pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Raj Mathur <raju@linux-delhi.org>
To: pgsql-sql@postgresql.org
Subject: Re: Substring
Date: Sat, 5 Sep 2009 08:02:09 +0530
Message-ID: <200909050802.10371.raju@linux-delhi.org> (raw)
In-Reply-To: <15318.85292.qm@web53905.mail.re2.yahoo.com>
References: <15318.85292.qm@web53905.mail.re2.yahoo.com>

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?

From your example the following brute-force method should work (not 
tested):

select * from voipdb where prefix like substring(string from 1 for 2) || 
'%' or prefix like substring(string from 1 for 3) || '%';

However, I don't understand why you'd want to search for both 'ab' and 
'abc' in the same query, since the first condition is a superset of the 
second one.

Regards,

-- Raju
-- 
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




view thread (22+ messages)  latest in thread

Message-ID: <200909050802.10371.raju@linux-delhi.org>
Permalink:  ../200909050802.10371.raju@linux-delhi.org/
Also on:    postgresql.org/message-id/200909050802.10371.raju@linux-delhi.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: raju@linux-delhi.org
  Subject: Re: Substring
  In-Reply-To: <200909050802.10371.raju@linux-delhi.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox