[Tutor] UPDATE, pyhthon+postgre

john johnf at jfcomputer.com
Wed Jun 1 09:23:00 EDT 2016


cursor1.execute("""UPDATE employee SET
name=%s,
add=%s,
add1=%s,
city=%s,
state_county=%s,
country=%s,
basic=%s,
WHERE group_code = %s""" %
(name,add,add1,city,state_county,country,basic,grpCode))

It appears that you are not required to provide any time or date since you created a default.  Of course that assumes you want today and now.

If that assumption is wrong then lookup "datetime".  To make life a little easier lookup the module "dateutil".  You would use either of those modules to convert your python input to the correct output for postgres (actually for any sql database).

Hint:  if the field requires a string you should place quotes around the placeholder as in '%s'.

Johnf






More information about the Tutor mailing list