Ring Rong
Ring Rong

Reputation: 1

Update with psycopg2

I have a problem with my code. When I connect to the database and want to execute a PSQL code line I get an error that says:

psycopg2.ProgrammingError: column "ew444" does not exist
LINE 1: UPDATE produkt_info SET antal = 4 WHERE modellnr = EW444

... even though I have "ew444" in my table

I've tried with the code below but it does not work for some reason. I can't figure out what the problem is.

con1 = connect()
con1.execute("UPDATE produkt_info SET antal = 4 WHERE modellnr = 
EW444")

I appreciate your help. Thanks in advance.

Upvotes: 0

Views: 733

Answers (2)

zvone
zvone

Reputation: 19332

This treats both modellnr and EW444 as columns names:

UPDATE produkt_info SET antal = 4 WHERE modellnr = EW444

You can see that from the error which says:

column "ew444" does not exist.

If you want to compare modellnr to string value 'EW444', you need to put it in quotes:

UPDATE produkt_info SET antal = 4 WHERE modellnr = 'EW444'

Upvotes: 1

hd1
hd1

Reputation: 34657

con1.execute("UPDATE produkt_info SET antal = 4 WHERE modellnr = %s", ('EW444',))

HTH

Upvotes: 0

Related Questions