@@ -870,9 +870,11 @@ def use_identity(element, compiler, **kw):
870870^^^^^^^^^^^^^^^^^^^^^
871871
872872The combination of ENUM and ARRAY is not directly supported by backend
873- DBAPIs at this time. In order to send and receive an ARRAY of ENUM,
874- use the following workaround type, which decorates the
875- :class:`_postgresql.ARRAY` datatype.
873+ DBAPIs at this time. Prior to SQLAlchemy 1.3.17, a special workaround
874+ was needed in order to allow this combination to work, described below.
875+
876+ .. versionchanged:: 1.3.17 The combination of ENUM and ARRAY is now directly
877+ handled by SQLAlchemy's implementation without any workarounds needed.
876878
877879.. sourcecode:: python
878880
@@ -917,10 +919,15 @@ def process(value):
917919Using JSON/JSONB with ARRAY
918920^^^^^^^^^^^^^^^^^^^^^^^^^^^
919921
920- Similar to using ENUM, for an ARRAY of JSON/JSONB we need to render the
921- appropriate CAST, however current psycopg2 drivers seem to handle the result
922- for ARRAY of JSON automatically, so the type is simpler::
922+ Similar to using ENUM, prior to SQLAlchemy 1.3.17, for an ARRAY of JSON/JSONB
923+ we need to render the appropriate CAST. Current psycopg2 drivers accomodate
924+ the result set correctly without any special steps.
925+
926+ .. versionchanged:: 1.3.17 The combination of JSON/JSONB and ARRAY is now
927+ directly handled by SQLAlchemy's implementation without any workarounds
928+ needed.
923929
930+ .. sourcecode:: python
924931
925932 class CastingArray(ARRAY):
926933 def bind_expression(self, bindvalue):
@@ -940,6 +947,10 @@ def bind_expression(self, bindvalue):
940947import datetime as dt
941948import re
942949
950+ from . import array as _array
951+ from . import hstore as _hstore
952+ from . import json as _json
953+ from . import ranges as _ranges
943954from ... import exc
944955from ... import schema
945956from ... import sql
@@ -1523,9 +1534,25 @@ def _on_metadata_drop(self, target, bind, checkfirst=False, **kw):
15231534 self .drop (bind = bind , checkfirst = checkfirst )
15241535
15251536
1526- colspecs = {sqltypes .Interval : INTERVAL , sqltypes .Enum : ENUM }
1537+ colspecs = {
1538+ sqltypes .ARRAY : _array .ARRAY ,
1539+ sqltypes .Interval : INTERVAL ,
1540+ sqltypes .Enum : ENUM ,
1541+ sqltypes .JSON .JSONPathType : _json .JSONPathType ,
1542+ sqltypes .JSON : _json .JSON ,
1543+ }
15271544
15281545ischema_names = {
1546+ "_array" : _array .ARRAY ,
1547+ "hstore" : _hstore .HSTORE ,
1548+ "json" : _json .JSON ,
1549+ "jsonb" : _json .JSONB ,
1550+ "int4range" : _ranges .INT4RANGE ,
1551+ "int8range" : _ranges .INT8RANGE ,
1552+ "numrange" : _ranges .NUMRANGE ,
1553+ "daterange" : _ranges .DATERANGE ,
1554+ "tsrange" : _ranges .TSRANGE ,
1555+ "tstzrange" : _ranges .TSTZRANGE ,
15291556 "integer" : INTEGER ,
15301557 "bigint" : BIGINT ,
15311558 "smallint" : SMALLINT ,
@@ -1917,6 +1944,22 @@ def get_column_specification(self, column, **kwargs):
19171944 colspec += " NOT NULL"
19181945 return colspec
19191946
1947+ def visit_check_constraint (self , constraint ):
1948+ if constraint ._type_bound :
1949+ typ = list (constraint .columns )[0 ].type
1950+ if (
1951+ isinstance (typ , sqltypes .ARRAY )
1952+ and isinstance (typ .item_type , sqltypes .Enum )
1953+ and not typ .item_type .native_enum
1954+ ):
1955+ raise exc .CompileError (
1956+ "PostgreSQL dialect cannot produce the CHECK constraint "
1957+ "for ARRAY of non-native ENUM; please specify "
1958+ "create_constraint=False on this Enum datatype."
1959+ )
1960+
1961+ return super (PGDDLCompiler , self ).visit_check_constraint (constraint )
1962+
19201963 def visit_drop_table_comment (self , drop ):
19211964 return "COMMENT ON TABLE %s IS NULL" % self .preparer .format_table (
19221965 drop .element
0 commit comments