0

I'm very new to SQL, and am trying to add a record to a table. I debugged my code and have already successfully made a database with a table called "weather." However, when I try to insert a record into the table and then print the table, no data prints in Terminal. I was wondering what I am doing wrong. Thank you.

conn = psycopg2.connect(database="postgres", user='postgres',password='password', host='127.0.0.1', port= '5432' )
conn.autocommit = True
cursor = conn.cursor()
cursor.execute('''INSERT INTO WEATHER (HUMIDITY, CITY, FEELSLIKE, HIGHLOW, TEMPERATURE) VALUES ('{%s}', '{%s}', '{%s}', '{%s}', '{%s}')'''), (humidityVal, cityVal, feelslikeVal, highlowVal, tempVal)
cursor.execute('''SELECT * from WEATHER''')
result = cursor.fetchall()
print(result)    
conn.close()
Bcat13
  • 37
  • 1
  • 1
  • 4
  • I can't reproduce getting neither errors nor 'print' output. I get one or the other, depending on how a flesh out your incomplete code. – jjanes Jun 09 '21 at 17:33

1 Answers1

0

I think the issue is in this line you don't need those brackets neither single quotes :

...
cursor.execute('INSERT INTO WEATHER (HUMIDITY, CITY, FEELSLIKE, HIGHLOW, TEMPERATURE) VALUES (%s, %s, %s, %s, %s)', (humidityVal, cityVal, feelslikeVal, highlowVal, tempVal))
...
eshirvana
  • 23,227
  • 3
  • 22
  • 38