T
T
twist2019-06-05 12:59:30
Python
twist, 2019-06-05 12:59:30

Why can't write to PostrgeSQL DB using Python?

I want to write data to the database using Python in this way

cursor.execute("INSERT INTO maps_data (sity, sh, dg, prem) VALUES (Город, 12.345, 12.345, тексттексттекст);")

But when executing, the following error occurs
cursor.execute("INSERT INTO maps_data (sity, sh, dg, prem) VALUES (City, 12.345, 12.345, texttexttext);") psycopg2.errors.UndefinedColumn: ERROR: column "City" is not exists
LINE 1: ...NSERT INTO maps_data (sity, sh, dg, prem) VALUES (City, 12....
Am I doing something wrong? Please tell me
Here is the code
cursor.execute("INSERT INTO maps_data (sity, sh, dg, prem) VALUES (Город, 12.345, 12.345, тексттексттекст);")

conn.commit()
   
cursor.close()
conn.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sviridov, 2019-06-05
@popy

Wrap strings in single quotes.

cursor.execute("INSERT INTO maps_data (sity, sh, dg, prem) VALUES ('Город', 12.345, 12.345, 'тексттексттекст');")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question