INTERVAL - should this be in base types?

Issue #2164 duplicate
Former user created an issue

using cast and INTERVAL seems to cause a problem: (note this code is corrupted by an issue tracker migration some years ago)

import sqlalchemy as sa
import sqlalchemy.dialects.postgresql as sa_pg
s1 = sa.select([week ago', sa_pg.DATE)](sa.cast('1))
print s1
s2 = sa.select([seconds', sa_pg.INTERVAL)](sa.cast('100))
print s2



AttributeError: 'GenericTypeCompiler' object has no attribute 'visit_INTERVAL'

The DATE cast works fine. The INTERVAL cast fails.

0.6.7 and 0.7b5 (current as of 7606:4d99799ee724070fe0fe7404f655854d223f6e93)

Comments (5)

  1. Mike Bayer repo owner

    INTERVAL is part of the SQL standard, but only Oracle and PG support it, and the SQL standard syntax is somewhat ridiculous. So INTERVAL is not in the base types module.

    In your case you are probably looking just for this:

    print s2.compile(dialect=sa_pg.dialect())
    

    but the bigger issue of INTERVAL, something to think about.

  2. Mike Bayer repo owner

    the test case is:

    import sqlalchemy as sa
    import sqlalchemy.dialects.postgresql as sa_pg
    s1 = sa.select([sa.cast('1 week ago', sa_pg.DATE)])
    print s1
    s2 = sa.select([sa.cast('100 seconds', sa_pg.INTERVAL)])
    print s2
    

    this now runs "fine" as the "print" case is handled by #3631. There's no pressure for a SQL-standard INTERVAL in the base right now as we have sqlalchemy.types.Interval for most generic use cases.

  3. Log in to comment