There are many different ways to specify an interval in SQL. Specifically, in PostgreSQL flavour, see https://www.postgresql.org/docs/9.1/datatype-datetime.html.
Is there a way to validate an arbitrary interval string in Python? Is there a way to convert it into a timedelta
? Can it be done without an explicit connection (and a call to the cursor)?
For some simple string like 31 minutes
I could write a custom validator which splits on space and validates that we have an integer and valid units. But what about strings like 1 year 2 months 3 days 4 hours 5 minutes 6 seconds
, P1Y2M3DT4H5M6S
, P0001-02-03T04:05:06
? I don't want to write my own validators for them all, so is there a better way?