1

I am trying to access sqlite db - test.db and running simple query "SELECT * FROM TABLE" and trying to save it in dataframe. It seems the code is fine as I searched and found similar codes that seem to work for others. NOTE: I am running the code in Jupyter iNotebook.

import sqlite3
import pandas as pd
con = sqlite3.connect('test.db')
myFrames = pd.read_sql_query("SELECT * FROM TABLE", con)

I get error

Error OperationalError: near "TABLE": syntax error

(lots of lines in between)

DatabaseError: Execution failed on sql 'SELECT * FROM TABLE': near "TABLE": syntax error

Also, This piece prints out rows very well. So connection is working

conn = sqlite3.connect("test.db")
cur = conn.cursor()
for row in cur.execute("SELECT * FROM test_rank"):
    print(row)
3
  • 2
    Table is reserved word in SQL. You need to give the real name of the table or rename otherwise. Commented Oct 25, 2017 at 21:09
  • @Mokshyam Thanks that worked. I have making silly mistake Commented Oct 25, 2017 at 21:20
  • 1
    No worries. All of us do. Tick the answer below. Commented Oct 25, 2017 at 21:21

1 Answer 1

1

Table is a reserved keyword. Replace it with the real name of the table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.