0

Below is the sql query that is working fine:


SELECT * FROM contracts.wires.monthly_data

But it is not working in python


import sqlite3 
connection = sqlite3.connect("contractsdbro") 
print(connection) 
crsr = connection.cursor() 
crsr.execute("SELECT * FROM contracts.wires.monthly_data")
ans= crsr.fetchall()

Error:

 sqlite3.OperationalError: near ".": syntax error
5
  • change * to field names and you should be through Commented Aug 25, 2019 at 3:33
  • @Satya : Just tried that ( "SELECT transaction_id, ag_amount FROM contracts.wires.monthly_data" working fine in sql ) ; still getting the same error in python. Commented Aug 25, 2019 at 3:37
  • can you explain what is contracts , wires , monthly_data Commented Aug 25, 2019 at 3:39
  • @Satya: contracts.wires.monthly_data is working fine when I run in SQL, so I think it should be contract is SchemaName and wire is TableName , so not sure what is third component. (not really an sql expert) Commented Aug 25, 2019 at 3:46
  • @Satya : think contracts is the database, wires is the schemaname and monthly_data is the tablename Commented Aug 25, 2019 at 3:50

1 Answer 1

1

As you can see in enter image description here

the valid syntax is schema-name.table-name (you have an extra component).

You haven't provided enough information, but just guessing

crsr.execute("SELECT * FROM monthly_data") 

should work.

You can use sqlite3 command-line tool to explore your database.

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

9 Comments

You might want to also include the corrected code to make this a complete answer.
@Diego : contracts.wires.monthly_data is working fine in SQL , so can you tell what is its equivalent in slqite3 ?
@TimBiegeleisen : think contracts is the database, wires is the schemaname and monthly_data is the tablename
@AnandKC - there's no schema names in SQLite unless you attach databases. If you're not attaching databases and only have one database you don't need anything other than select * from monthly_data.
@GIS-Jonathan : Thanks, I have multiple databases , in that case what should be my command
|

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.