Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Data Science by (18.4k points)
edited by

I added a bunch of pandas data frames as individual tables to an SQLite database, but I didn't realize one of the names had periods in it. When I tried to SELECT and read that table I got this error below:

pandas.io.sql.DatabaseError: Execution failed on sql 'SELECT * from A.J._Doe': near ".": syntax error

Is there a way to read that table with the period in the name? The other names without the periods work just fine.

name = "A.J._Doe"

pd.read_sql_query("SELECT * from " + name, conn)  # Gives the above error message

1 Answer

0 votes
by (36.8k points)
edited by

In SQLite, you may escape the object name (e.g. table, column, database, etc.) using the double quotes, so try:

name = "A.J._Doe"

sql = 'SELECT * FROM "' + name + '"'

pd.read_sql_query(sql, conn)

If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...