Reputation: 185
I need to update a column without overwriting its content. I tried with the sqlite3 syntax 'concat' which is ||, but it didn't work. This way the data is not saved and the column remains empty.
data = ('Hello!', 1)
sql = """UPDATE dbase SET observation = observation || ? WHERE id = ?;"""
c = conn.cursor()
c.execute(sql, data)
conn.commit()
conn.close()
Any idea?
Upvotes: 0
Views: 247
Reputation: 521073
and the column remains empty
If the current of observation
be NULL
, then concatenating anything to it will also just generate NULL
. One option might be:
data = ('Hello!', 1,)
sql = "UPDATE dbase SET observation = COALESCE(observation, '') || ? WHERE id = ?;"
c = conn.cursor()
c.execute(sql, data)
Upvotes: 1