Skip to content

Commit

Permalink
- add a section for ARRAY of JSON to complement ARRAY of ENUM. refere…
Browse files Browse the repository at this point in the history
…nces #3467

Change-Id: I9836b842be01ef24138071fa022d80f5f77be14f
  • Loading branch information
zzzeek committed Jan 5, 2017
1 parent cd95d4a commit 2b4d028
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/sqlalchemy/dialects/postgresql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,29 @@ def process(value):
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
Expand Down

0 comments on commit 2b4d028

Please sign in to comment.