I have 2 strings which represent:
- date- dd/mm/yyyy hh:mm and I need to convert it to timestamp without time zone
- start_time/end_tiime- hh:mm:ss and I need to convert it time without time zone
I need to do this in order to add them to a sql query. which looks like this:
sql = '''
INSERT INTO myTable (date, start_time, end_time)
VALUES (%s ,%s, %s, %s);'''
params = [timestamp, start_time, end_time]
self.cursor.execute(sql, params)
psycopg2Python strings, floats, integers, datetime object and it will convert them by itself to compatible SQL type if not you could register an adapter. There might be complications such as different versions of postgresql treattimestampwith/without time zone types differently,psycopg2might expose whether postgresql compiled with integers or floats for timestamp, time. You could see what would be sent to the database by callingcursor.mogrify().