diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-01-05 10:02:58 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-01-05 10:03:55 -0500 |
commit | 2b4d028a69270c1c7918281a60280dd0b65963a2 (patch) | |
tree | a0070d863aaadc541462df3b1ac39904641037fe /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | cd95d4a5b928a6bc4f07c988ba3791a0a63c8d15 (diff) | |
download | sqlalchemy-2b4d028a69270c1c7918281a60280dd0b65963a2.tar.gz |
- add a section for ARRAY of JSON to complement ARRAY of ENUM. references #3467
Change-Id: I9836b842be01ef24138071fa022d80f5f77be14f
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index c5021249e..339536dd4 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -814,6 +814,29 @@ This type is not included as a built-in type as it would be incompatible with a DBAPI that suddenly decides to support ARRAY of ENUM directly in a new version. +.. _postgresql_array_of_json: + +Using JSON/JSONB with ARRAY +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Similar to using ENUM, for an ARRAY of JSON/JSONB we need to render the +appropriate CAST, however current psycopg2 drivers seem to handle the result +for ARRAY of JSON automatically, so the type is simpler:: + + + class CastingArray(ARRAY): + def bind_expression(self, bindvalue): + return sa.cast(bindvalue, self) + +E.g.:: + + Table( + 'mydata', metadata, + Column('id', Integer, primary_key=True), + Column('data', CastingArray(JSONB)) + ) + + """ from collections import defaultdict import re |