to issue the appropriate CREATE TYPE/DROP TYPE
commands as needed, supports unicode labels, supports
reflection. [ticket:1511]
-
+
+ - INTERVAL supports an optional "precision" argument
+ corresponding to the argument that PG accepts.
+
- using new dialect.initialize() feature to set up
version-dependent behavior.
This is postgresql.DOUBLE_PRECISION in 0.6.
[ticket:1085]
+ - Added support for reflecting the INTERVAL YEAR TO MONTH
+ and INTERVAL DAY TO SECOND syntaxes of the INTERVAL
+ type. [ticket:460]
+
- Corrected the "has_sequence" query to take current schema,
or explicit sequence-stated schema, into account.
[ticket:1576]
class INTERVAL(sqltypes.TypeEngine):
__visit_name__ = 'INTERVAL'
+ def __init__(self, precision=None):
+ self.precision = precision
+
+ def adapt(self, impltype):
+ return impltype(self.precision)
+
PGInterval = INTERVAL
class BIT(sqltypes.TypeEngine):
'bytea' : BYTEA,
'boolean' : BOOLEAN,
'interval':INTERVAL,
+ 'interval year to month':INTERVAL,
+ 'interval day to second':INTERVAL,
}
return "TIME " + (type_.timezone and "WITH" or "WITHOUT") + " TIME ZONE"
def visit_INTERVAL(self, type_):
- return "INTERVAL"
+ if type_.precision is not None:
+ return "INTERVAL(%d)" % type_.precision
+ else:
+ return "INTERVAL"
def visit_BIT(self, type_):
return "BIT"
else:
numericprec, numericscale = charlen.split(',')
charlen = False
- if attype == 'double precision':
+ elif attype == 'double precision':
numericprec, numericscale = (53, False)
charlen = False
- if attype == 'integer':
+ elif attype == 'integer':
numericprec, numericscale = (32, 0)
charlen = False
args = []
import datetime
from sqlalchemy import *
from sqlalchemy.orm import *
-from sqlalchemy import exc, schema
+from sqlalchemy import exc, schema, types
from sqlalchemy.dialects.postgresql import base as postgresql
from sqlalchemy.engine.strategies import MockEngineStrategy
from sqlalchemy.test import *
global metadata, table
metadata = MetaData(testing.db)
+ # create these types so that we can issue
+ # special SQL92 INTERVAL syntax
+ class y2m(types.UserDefinedType, postgresql.INTERVAL):
+ def get_col_spec(self):
+ return "INTERVAL YEAR TO MONTH"
+
+ class d2s(types.UserDefinedType, postgresql.INTERVAL):
+ def get_col_spec(self):
+ return "INTERVAL DAY TO SECOND"
+
table = Table('sometable', metadata,
Column('id', postgresql.PGUuid, primary_key=True),
Column('flag', postgresql.PGBit),
Column('addr', postgresql.PGInet),
Column('addr2', postgresql.PGMacAddr),
Column('addr3', postgresql.PGCidr),
- Column('doubleprec', postgresql.DOUBLE_PRECISION)
-
+ Column('doubleprec', postgresql.DOUBLE_PRECISION),
+ Column('plain_interval', postgresql.INTERVAL),
+ Column('year_interval', y2m()),
+ Column('month_interval', d2s()),
+ Column('precision_interval', postgresql.INTERVAL(precision=3))
)
metadata.create_all()
+
+ # cheat so that the "strict type check"
+ # works
+ table.c.year_interval.type = postgresql.INTERVAL()
+ table.c.month_interval.type = postgresql.INTERVAL()
@classmethod
def teardown_class(cls):
t = Table('sometable', m, autoload=True)
self.assert_tables_equal(table, t, strict_types=True)
-
+ assert t.c.plain_interval.type.precision is None
+ assert t.c.precision_interval.type.precision == 3
class MatchTest(TestBase, AssertsCompiledSQL):
__only_on__ = 'postgresql'