summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-03-16 11:01:20 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-03-16 11:01:20 -0400
commitf75ea6945cf2f0b727558e2f5c247a94cf2668bf (patch)
tree70829619e5d3ceb87a2d1f559cf1b3142541a1a0 /lib/sqlalchemy/dialects/postgresql
parent83f8c4d24122340179f72863170dcfb74aa55897 (diff)
downloadsqlalchemy-f75ea6945cf2f0b727558e2f5c247a94cf2668bf.tar.gz
- Fixed the BIT type to allow a "length" parameter, "varying"
parameter. Reflection also fixed. [ticket:2073]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 0848bb0dc..8bceeef65 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -178,8 +178,14 @@ PGInterval = INTERVAL
class BIT(sqltypes.TypeEngine):
__visit_name__ = 'BIT'
- def __init__(self, length=1):
- self.length= length
+ def __init__(self, length=None, varying=False):
+ if not varying:
+ # BIT without VARYING defaults to length 1
+ self.length = length or 1
+ else:
+ # but BIT VARYING can be unlimited-length, so no default
+ self.length = length
+ self.varying = varying
PGBit = BIT
@@ -404,7 +410,8 @@ ischema_names = {
'inet': INET,
'cidr': CIDR,
'uuid': UUID,
- 'bit':BIT,
+ 'bit': BIT,
+ 'bit varying': BIT,
'macaddr': MACADDR,
'double precision' : DOUBLE_PRECISION,
'timestamp' : TIMESTAMP,
@@ -648,7 +655,13 @@ class PGTypeCompiler(compiler.GenericTypeCompiler):
return "INTERVAL"
def visit_BIT(self, type_):
- return "BIT(%d)" % type_.length
+ if type_.varying:
+ compiled = "BIT VARYING"
+ if type_.length is not None:
+ compiled += "(%d)" % type_.length
+ else:
+ compiled = "BIT(%d)" % type_.length
+ return compiled
def visit_UUID(self, type_):
return "UUID"
@@ -1124,6 +1137,7 @@ class PGDialect(default.DefaultDialect):
if charlen:
charlen = charlen.group(1)
kwargs = {}
+ args = None
if attype == 'numeric':
if charlen:
@@ -1147,6 +1161,12 @@ class PGDialect(default.DefaultDialect):
if charlen:
kwargs['precision'] = int(charlen)
args = ()
+ elif attype == 'bit varying':
+ kwargs['varying'] = True
+ if charlen:
+ args = (int(charlen),)
+ else:
+ args = ()
elif attype in ('interval','interval year to month',
'interval day to second'):
if charlen: