]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add a section for ARRAY of JSON to complement ARRAY of ENUM. references #3467
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Jan 2017 15:02:58 +0000 (10:02 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Jan 2017 15:04:29 +0000 (10:04 -0500)
Change-Id: I9836b842be01ef24138071fa022d80f5f77be14f
(cherry picked from commit 2b4d028a69270c1c7918281a60280dd0b65963a2)

lib/sqlalchemy/dialects/postgresql/base.py

index 3266677100b6b985ab5ffdc984e323de916d5687..9d596dfd3289f11909080ddfaf932efb26dca9bf 100644 (file)
@@ -563,6 +563,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