How do I find the position of a character in a SQLite column?

Viewed 27009

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.

9 Answers

SELECT instr(COLUMN, '@') FROM TABLE

I'm using Python, but this can be done using the command line tools.

This solution uses Regex to extract a date:

import re
import sqlite3

def get_date_from_path(item: str, expr: str):
    return re.search(pattern=expr, string=item).group()

conn = sqlite3.connect(database=r'Name.db')
conn.create_function("GET_DATE_FROM_PATH", 2, get_date_from_path)

SELECT GET_DATE_FROM_PATH('C:\reports\report_20190731.csv', r'[0-9]{8}');
Related