If the result "joe@stackoverflow.com
" and I want to find the position of the @
symbol (3). Is it possible? It does not appear that SQLite has the equivalent of INSTR
, LOCATE
, POSITION
or any such function.
SELECT ?('joe@stackoverflow.com')
Update I ended up registering a custom extension function, but was surprised that I had to.
Use
charindex('c', column, 0)
it depends on the version of SQLite.
Here's a basic resource you might like: http://sqlzoo.net/howto/source/z.dir/tip238311/sqlite
I'm using Python, but this can be done using the command line tools.
This solution uses Regex to extract a date:
Don't know whether this is a recent addition, but the
INSTR
function will indeed find the 1st instance.SELECT instr(COLUMN, '@') FROM TABLE
As you can see here, charindex is not in SQLite standard package(At least in 3.6.2 version that i use). But this extension (extension-functions.c) has Charindex, which is basically the same as the VB instr.
To add these functions to sqlite:
We have to compile the C source code to make the sqlite extension (Assuming you are on Windows):
Install the mingw compiler, small and easy to do.
copy sqlite3.h to the same folder
gcc -fPIC -lm -shared extension-functions.c -o libsqlitefunctions.dll
fireup sqlite
select load_extension('libsqlitefunctions.dll')
There are other string and math functions as well.