Click here to Skip to main content
15,888,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to update postgresql table based on the function output but it is not updating , kindly guide

What I have tried:

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)
Posted
Updated 18-Oct-20 0:03am

1 solution

I think you need to change:
UPDATE table_name
into:
UPDATE contact
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900