1

Here is a snippet of my code. I read the date from a string and trying to insert into a redshift database, but I'm getting errors while passing the dates.

The dates passed are in the following format: dd-mm-yyyy

Failed to insert record into school_holidays table date/time field value out of range: "29-01-2019" HINT: Perhaps you need a different "datestyle" setting.

postgres_insert_query = """ INSERT INTO vacation (jurid, startdate, enddate, description) VALUES (%s,%s,%s,%s)"""
record_to_insert = (state, startdate, enddate, description)
cursor.execute(postgres_insert_query, record_to_insert)
user2496011
  • 67
  • 3
  • 12
  • I can manually insert the record using the to_date('29-01-2019','dd-mm-yyyy') however I need to understand how to do this properly with psycopg2 in Python. Obviously these are passed as strings. How do I nominate the string is a date and in the dd-mm-yyyy format? – user2496011 Apr 11 '19 at 23:40
  • Try execute the set datestyle command `SET datestyle = "ISO, DMY";`before you execute the insert query – danielR9 Apr 11 '19 at 23:43

0 Answers0