I have an sqlite db called clients.db with a table called prices. Within the table I have columns ['date', 'xyz', 'abc', 'sta, 'vert']. I am accessing the database from python 3.
I can get a specific number easily enough using:
conn = sqlite3.connect('clients.db')
c = conn.cursor()
c.execute('''SELECT "xyz" FROM prices WHERE date=?''', ('2019-01-07', ))
conn.close()
print(c.fetchone()[0])
This returns 1902 as expected.
However when I try the below, instead of the expected number I get xyz.
conn = sqlite3.connect('clients.db')
c = conn.cursor()
c.execute('''SELECT ? FROM prices WHERE date=?''', ('xyz', '2019-01-07', ))
conn.close()
print(c.fetchone()[0])
and when I add a =? I get sqlite3.OperationalError: near "=": syntax error:
conn = sqlite3.connect('clients.db')
c = conn.cursor()
c.execute('''SELECT =? FROM prices WHERE date=?''', ('xyz', '2019-01-07', ))
conn.close()
print(c.fetchone()[0])