diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-11-01 22:47:14 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-11-01 22:47:14 +0000 |
commit | e8854fe945e94d0fe654e83397c47f8b0fb1f1e8 (patch) | |
tree | bb6b4b9c09a476cb859fcdbc29863e5872ec3fc1 /lib/sqlalchemy | |
parent | fb6be4d35906ccc822634a7657ec109b5d8cbb7f (diff) | |
download | sqlalchemy-e8854fe945e94d0fe654e83397c47f8b0fb1f1e8.tar.gz |
- INTERVAL supports an optional "precision" argument
corresponding to the argument that PG accepts.
- Added support for reflecting the INTERVAL YEAR TO MONTH
and INTERVAL DAY TO SECOND syntaxes of the INTERVAL
type. [ticket:460]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 17 | ||||
-rw-r--r-- | lib/sqlalchemy/test/testing.py | 3 |
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 9570dae57..c41d5b359 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -105,6 +105,12 @@ PGMacAddr = MACADDR 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): @@ -238,6 +244,8 @@ ischema_names = { 'bytea' : BYTEA, 'boolean' : BOOLEAN, 'interval':INTERVAL, + 'interval year to month':INTERVAL, + 'interval day to second':INTERVAL, } @@ -426,7 +434,10 @@ class PGTypeCompiler(compiler.GenericTypeCompiler): 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" @@ -839,10 +850,10 @@ class PGDialect(default.DefaultDialect): 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 = [] diff --git a/lib/sqlalchemy/test/testing.py b/lib/sqlalchemy/test/testing.py index 654153adb..369aa3a6f 100644 --- a/lib/sqlalchemy/test/testing.py +++ b/lib/sqlalchemy/test/testing.py @@ -639,7 +639,8 @@ class ComparesTables(object): eq_(c.nullable, reflected_c.nullable) if strict_types: - assert type(reflected_c.type) is type(c.type), "Type '%s' doesn't correspond to type '%s'" % (reflected_c.type, c.type) + assert type(reflected_c.type) is type(c.type), \ + "Type '%s' doesn't correspond to type '%s'" % (reflected_c.type, c.type) else: self.assert_types_base(reflected_c, c) |