1

I have a table data in a database data.sqlite:

'my_path/data.sqlite'

A B
0 0
1 1
0 1
1 0

I would like to add a new column to this table, where each value = 1 if A = B, or 0 otherwise.

I can create a new column by doing:

conn = sqlite3.connect('my_path/data.sqlite')
cur = conn.cursor()
cur.execute("ALTER TABLE data ADD COLUMN Agreement")
conn.commit()

A B Agreement
0 0
1 1
0 1
1 0

I then try a conditional statement: where A and B are equal using the UPDATE SET CASE function a la Conditional update in SQLite:

cur.execute("UPDATE data"
            "SET Agreement = CASE WHEN A == B THEN 1 ELSE 0 END")
cur.commit()

But I keep getting:

OperationalError: near "Agreement": syntax error

What am I doing wrong?

Chuck
  • 3,664
  • 7
  • 42
  • 76

0 Answers0