Skip to content

Commit 91f1423

Browse files
author
Matt George
committed
varchar with no length == NullType
On redshift, a variable character field with no lenth attached is considered a nulltype field.
1 parent 13266db commit 91f1423

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

redshift_sqlalchemy/dialect.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from sqlalchemy.dialects.postgresql.psycopg2 import PGDialect_psycopg2
22
from sqlalchemy.engine import reflection
33
from sqlalchemy import util, exc
4+
from sqlalchemy.types import VARCHAR, NullType
45

56
class RedshiftDialect(PGDialect_psycopg2):
67
@reflection.cache
@@ -43,3 +44,10 @@ def set_isolation_level(self, connection, level):
4344
)
4445

4546
connection.set_isolation_level(level)
47+
48+
def _get_column_info(self, name, format_type, default,
49+
notnull, domains, enums, schema):
50+
column_info = super(RedshiftDialect, self)._get_column_info(name, format_type, default, notnull, domains, enums, schema)
51+
if isinstance(column_info['type'], VARCHAR) and column_info['type'].length is None:
52+
column_info['type'] = NullType()
53+
return column_info

0 commit comments

Comments
 (0)