我是一名postgres新手,在使用Python查詢postgresql中的文本字段時遇到了一些問題。什麼是正確的語法,將允許我從表「jivemessage」中的數據庫「postgres」搜索列「body」的內容?正確的Postgresql語法
try:
conn = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='<password>'")
except:
print "cannot connect"
i = 'test'
cur = conn.cursor()
cur.execute('SELECT * from jivemessage WHERE body LIKE "%'+i+'%"')
不斷收到以下錯誤:
ProgrammingError: column "%test%" does not exist
感謝您的幫助。
如果你正在尋找這樣的身體,你可能想看看postgresql的全文搜索索引。 – cmd
你的報價混淆了。這裏的基本是: selecttable from sometable where somefield like'%text%'; 請注意這裏的單引號。 –