Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to select a column on sqlite3 database

I am trying to select a particular column of a table in a sqlite database. I am using the following:

cursor = connection.execute('select Case from SUMMARY')

Even though the column name is correct, whenever I run the code, i receive the following error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The same happens when I try to fetch the column index.

Whenever i try any other column, I can fetch all the column’s data.

OperationalError                          Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15288/2883478922.py in <module>
      1 import sqlite3
      2 connection = sqlite3.connect("../DB_Cases.sqlite")
----> 3 cursor = connection.execute('select Case from SUMMARY') 

OperationalError: near "from": syntax error

>Solution :

case is reserved keyword in SQLite.

Using double quotes in the query as mentioned in the SQLite documentation should get your query working.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading