My database has a number of sessions.
@schema
class Session(dj.Manual):
definition = """
-> Subject
session_datetime: datetime
"""
I could fetch or delete them as follows.
total_sessions = session.Session # N=4
total_sessions.fetch() # Successful output
total_session.delete() # Successful cascading delete prompt
If I'm only interested in sessions after a given year/month, I can generate a query with a relative restriction, fully specifying datetime
.
later_sessions1 = (session.Session & 'session_datetime > "2021-06-01 12:00:00"') # N=2
later_sessions1.fetch() # Successful output
later_sessions1.delete() # Successful cascading delete prompt
If I don't fully specify datetime
, I can still fetch the data, but deletion fails.
later_sessions2 = (session.Session & 'session_datetime > "2021-06"') # N=2
later_sessions2.fetch() # Successful output
later_sessions2.delete() # OperationalError: (1292, "Incorrect datetime value: '2021-06' for column 'session_datetime' at row 1")
Is this intended? Should fetch()
and delete()
fail under the same conditions?
EDIT: calling make_sql()
on later_sessions2
returns the following
'SELECT DISTINCT `subject`,`session_datetime` FROM `test_session`.`session` WHERE(session_datetime > "2021-06")'
If called on the fully specified later_sessions1
, the last WHERE
component includes the full datetime.