summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-11-01 22:47:14 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-11-01 22:47:14 +0000
commite8854fe945e94d0fe654e83397c47f8b0fb1f1e8 (patch)
treebb6b4b9c09a476cb859fcdbc29863e5872ec3fc1 /lib/sqlalchemy/dialects/postgresql
parentfb6be4d35906ccc822634a7657ec109b5d8cbb7f (diff)
downloadsqlalchemy-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/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py17
1 files changed, 14 insertions, 3 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 = []