PostgreSQL 24:00:00 time provokes exception

Issue #3533 closed
Hasier created an issue

In PostgreSQL, a value of 24:00:00 in a time type column is valid, but Python only accepts a max of 23:59:59.999999. Therefore it breaks with 'ValueError: hour must be in 0..23' when retrieving it.

P.S.: I guess it would be a better practice to store 23:59:59.99 in the DB as the SQL standard says, but I think it should be somewhat managed anyway, transforming the retrieved value to 23:59:59.99.

Comments (4)

  1. Mike Bayer repo owner

    SQLAlchemy isn't raising a ValueError here, that is your driver.

    Feel free to report to the psycopg2 project

    import psycopg2
    
    conn = psycopg2.connect(
        user="scott", password="tiger", host="localhost", database="test")
    cursor = conn.cursor()
    
    cursor.execute("create table test_date (value time)")
    cursor.execute("insert into test_date (value) values ('24:00:00')")
    
    cursor.execute("select value from test_date")
    row = cursor.fetchone()
    print row
    

    output:

    #!
    
    
    Traceback (most recent call last):
      File "test.py", line 11, in <module>
        row = cursor.fetchone()
    ValueError: hour must be in 0..23
    
  2. Hasier reporter

    Oh ok. I just saw the error coming from python2.7/site-packages/sqlalchemy/engine/result.py so reported here, sorry about that :) And thanks for the tips!

  3. Log in to comment