区别于=&引用;及;匹配“;在sqlite3中,Python是什么?
两个类似的问题:区别于=&引用;及;匹配“;在sqlite3中,Python是什么?,python,select,sqlite,Python,Select,Sqlite,两个类似的问题: firstQuery = "select * from table_name where column_name = match_value" secondQuery = "select * from table_name where column_name match match_value" 使用执行第一个可以正常工作,但执行第二个会抛出: sqlite3.OperationalError: unable to use function MATCH in the requ
firstQuery = "select * from table_name where column_name = match_value"
secondQuery = "select * from table_name where column_name match match_value"
使用执行第一个可以正常工作,但执行第二个会抛出:
sqlite3.OperationalError: unable to use function MATCH in the requested context
有人能给我解释一下为什么会这样吗?谢谢。来自sqlite文档:
MATCH运算符是MATCH()应用程序定义函数的特殊语法。默认match()函数实现会引发异常,对任何事情都没有实际用处。但是扩展可以用更有用的逻辑覆盖match()函数
在Python2.7中
import sqlite3
conn = sqlite3.connect(":memory:")
cur = conn.cursor()
cur.execute("create table test(v1 text, v2 int)")
for index in range(5):
cur.execute("insert into test values(\"python ###{index}\", {index})".format(index=index))
import re
def matchPattern(pattern, value):
return bool(re.match(pattern, value)) # return true or false
# creating the 'match' function.
conn.create_function("matchPattern", 2, matchPattern)
跑步
#打印->[“python 1”,1),“python 2”,2),…,…]
i = cur.execute("select v1, v2 from test where matchPattern('python', v1)")
print i.fetchall()