summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Locke <tlocke@tlocke.org.uk>2015-01-03 16:59:17 +0000
committerTony Locke <tlocke@tlocke.org.uk>2015-01-03 16:59:17 +0000
commit17e03a0ea86cd92816b4002a203b2b0b2c1a538a (patch)
tree8f008e511dc8bbba9675e6868b0ee79fc186b0dc
parentc93706fa3319663234e3ab886b65f055bf9ed5da (diff)
downloadsqlalchemy-pr/132.tar.gz
Changed pg8000 dialect to cope with native JSONpr/132
For versions > 1.10.1 pg8000 returns de-serialized JSON objects rather than a string. SQL parameters are still strings though.
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pg8000.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py
index 17d83fa61..4bb376a96 100644
--- a/lib/sqlalchemy/dialects/postgresql/pg8000.py
+++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py
@@ -72,6 +72,7 @@ from .base import (
PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext,
_DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES)
import re
+from sqlalchemy.dialects.postgresql.json import JSON
class _PGNumeric(sqltypes.Numeric):
@@ -102,6 +103,15 @@ class _PGNumericNoBind(_PGNumeric):
return None
+class _PGJSON(JSON):
+
+ def result_processor(self, dialect, coltype):
+ if dialect._dbapi_version > (1, 10, 1):
+ return None # Has native JSON
+ else:
+ return super(_PGJSON, self).result_processor(dialect, coltype)
+
+
class PGExecutionContext_pg8000(PGExecutionContext):
pass
@@ -143,7 +153,8 @@ class PGDialect_pg8000(PGDialect):
PGDialect.colspecs,
{
sqltypes.Numeric: _PGNumericNoBind,
- sqltypes.Float: _PGNumeric
+ sqltypes.Float: _PGNumeric,
+ JSON: _PGJSON,
}
)