Как обновить таблицу postgresql с помощью Python
я пытаюсь обновить таблицу postgresql на основе вывода функции , но она не обновляется, любезно руководство
Что я уже пробовал:
conn = psycopg2.connect(database = database, user = user_name, password = password, host = host, port = port) print("Database Connection Successful") cursor = conn.cursor() query = "select id from contact where owner_company_id =7295373" cursor.execute(query) contact = list(cursor.fetchall()) print(contact) for info in contact: id = info[0] print(id) ivurl = f'{api}/company/{id}/contacts?' payload: Dict[str, Union[bool, int]] = {'id': True} response = get_iv_response(url=ivurl, payload=payload) email_contact_totalresult: int = response.get('totalResults') email = int(email_contact_totalresult) payload: Dict[str, Union[bool, int]] = {'name': True} response = get_iv_response(url=ivurl, payload=payload) phone_contact_totalresult: int = response.get('totalResults') phone = int(phone_contact_totalresult) print ("here") if email > 0 or phone > 0: print (f"{id} has contacts") else : print (f"{id} doesnot has contacts") update_query = (f"UPDATE table_name set has_contact = true where id = {id}") print(update_query) cursor.execute(update_query)