Reputation: 989
I'm trying to find a way to select a row in sqlite from Python. Say I have a table soft drinks
with columns drink
and price
, with the primary key being drink name
. I want to select coke
out of drink
name. How would I do this without looping through every single entry?
Here's my code:
conn = sqlite3.Connection("database.db")
curs = conn.cursor()
curs.execute("create table soft drinks (drink name TEXT, drink TEXT, price INTEGER)"
curs.execute("insert into soft drinks (drink name, drink, price) values ("coke", "whatever", 89)")
I'm looking for a command something like curs.execute(select "coke" from soft drinks)
and it will return the whole row.
Upvotes: 2
Views: 9289
Reputation: 24506
SQLite uses quotation marks as column identifiers, so you'd need to put quotation marks around the column and table name: SELECT * FROM "soft drinks" WHERE "drink name" = 'Coke';
Upvotes: 2