In Postgresql psycopg2, can we change null values to blanks?

I’m using Python 3.11 on Windows 10 and psycopg2 v2.9.9 which is here on pypi. I’m still learning Python, I’m no expert.

I’m reading some records from a Postgresql database and once in a while a date field called enddate in my program, is null in the database. psycopg2 changes these to None. This is data from a timesheet system I’m looking at and sometimes people forget to log out so they have a null enddate. which produced an error for the first time today.

Since I just got the error today and I’ve run this program at least 40 times over 3+ weeks and using different criteria for dates, I’m thinking this blank enddate is a rare occurrence.

But I have to account for it and at least display an error message for this case to help me troubleshoot the program, and others interpret missing data. (Each time the program is run the error messages are saved to an error log specific to the time and date it was run.)

Question: Is it better to leave enddate as None so I can do this in my program?

if not enddate: 
    print("ERROR: enddate is null")

EDIT: I have to get the startdate, starttime, enddate, and endtime to calculate how many hours passed.

That can only be answered by you based on your requirements :slight_smile: If you decide there is a sensible value you can use instead, however, you may want to use the COALESCE function in your query to replace nulls. I would not suggest replacing with blanks as in your question title though, that seems like it would make things worse.