On Sun, 26 Oct 2014 15:27:24 +0300
Baruch Burstein <bmburst...@gmail.com> wrote:

> I need to get the path with the
> first 2 parts stripped off. Currently I am doing:
> 
>         substr(path, 4+instr(substr(path,4),'/'))
> 
> But that seems long and probably inefficient.
> What is the best/simplest way to find the second occurrence of the
> '/' in a string?

Fast is fast enough.  If your SQL solves your problem acceptably fast,
you're done.  

If you need something faster, you could implement support for
regular expressions.  Posix filename rules are very strict: the only
disallowed characters are '/' and NUL.  A simple regex returns the Nth
occurence of a pattern.  I would expect such a solution to move the
performance constraint from the SQL interpreter (if that's where it is)
to I/O.  

My example implementation is at
http://www.schemamania.org/sql/sqlite/udf/regex.pdf  Note however I
wrote it as a user-defined function before I understood that REGEXP is a
supported keyword in the SQLite syntax.  If you implement a regexp()
user function, you have access to it as an SQL operator, not just as a
UDF.  


--jkl

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to