> >
> > Given that tablename is "voipdb"; I wonder if OP really
> wants to write
> > a query that finds the row where argument to function
> matches the most
> > number of leading characters in "prefix".
> >
> > If voipdb table contains: ab, abc, def, defg; then calling
> function
> > with "abc" or "abcd" returns "abc" and calling function with "defh"
> > returns "def".
> >
> > If this is the real problem to be solved; then brute force is one
> > solution; but I'm left wondering if a single query might return
> > desired result (a single row).
>
> Something like this may help in that case (note, we're
> completely in the realm of creating imaginary problems and
> solving them now :)
>
> select * from voipdb where prefix <= string order by prefix
> desc limit 1;
>
> Regards,
>
> -- Raju
Hum, I wonder if some kind of best-matching query is what you are looking
for:
SELECT *
FROM voipdb
WHERE prefix IN (
SELECT substr(string, 1, i)
FROM generate_series(1, length(string)) i
);
Cheers,
Fernando.
--
Sent via pgsql-sql mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql