1

I have a sqlite database filled with stuff, and I am currently writing code to search for and extract the data I want. Here's where I slammed into trouble:

conn = sqlite3.connect("ensembl.db")
cur = conn.cursor()
...
cur.execute('SELECT b.chr,(b.start-e.start) as StartD, (b.end-e.end) as EndD,b.tcon,b.tname,b.gname FROM ensembl e blast b WHERE b.tcon=? AND b.tname=e.tname AND b.gname=e.gname AND b.chr=e.chr',tcon)
        print cur.fetchone()

This returns the error:

File "data.py", line 12, in <module>
    cur.execute('SELECT b.chr,(b.start-e.start) as StartD, (b.end-e.end) as EndD,b.tcon,b.tname,b.gname FROM ensembl e blast b WHERE b.tcon=? AND b.tname=e.tname AND b.gname=e.gname AND b.chr=e.chr',tcon)
sqlite3.OperationalError: near "blast": syntax error

I don't know what this syntax error is that python is referring to -- I've done queries similar (granted, not quite as complicated) to this before in sqlite&python and they have worked. I have tried various other ways but none seemed to work... am I missing something really simple?

Also, another question -- what would be the best way to individually extract the columns from the results once I get this working? I have used cur.fetchone() before and assigned it to a single variable for queries returning just one thing, but not sure if it will work for queries returning multiple things.

2
  • You might consider removing the python-tag. You have an SQL-syntax problem. Commented Feb 28, 2013 at 22:28
  • Please make a separate question for your second question. Commented Feb 28, 2013 at 22:29

2 Answers 2

2

You need comma-separate the tables in the FROM-section:

[..] FROM ensembl e, blast b [..]

.

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

Comments

1

To extract the colum you could map a lambda function to a list of lists i.e. map( lamda x: x[0], listoflist) for the first column, map(lambda x: x[1], listoflists) for the second etc.

you could even create a lambda function that does this, i.e.

extractor = lambda i,l : map(lambda x: x[i],l)

and use

extractor(i,listofLists)

to get a list of the i-th column.

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.