MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / ARRAY

Class ARRAY

lib/sqlalchemy/dialects/postgresql/array.py:253–501  ·  view source on GitHub ↗

PostgreSQL ARRAY type. The :class:`_postgresql.ARRAY` type is constructed in the same way as the core :class:`_types.ARRAY` type; a member type is required, and a number of dimensions is recommended if the type is to be used for more than one dimension:: from sqlalchemy.dia

Source from the content-addressed store, hash-verified

251
252
253class ARRAY(sqltypes.ARRAY[_T]):
254 """PostgreSQL ARRAY type.
255
256 The :class:`_postgresql.ARRAY` type is constructed in the same way
257 as the core :class:`_types.ARRAY` type; a member type is required, and a
258 number of dimensions is recommended if the type is to be used for more
259 than one dimension::
260
261 from sqlalchemy.dialects import postgresql
262
263 mytable = Table(
264 "mytable",
265 metadata,
266 Column("data", postgresql.ARRAY(Integer, dimensions=2)),
267 )
268
269 The :class:`_postgresql.ARRAY` type provides all operations defined on the
270 core :class:`_types.ARRAY` type, including support for "dimensions",
271 indexed access, and simple matching such as
272 :meth:`.types.ARRAY.Comparator.any` and
273 :meth:`.types.ARRAY.Comparator.all`. :class:`_postgresql.ARRAY`
274 class also
275 provides PostgreSQL-specific methods for containment operations, including
276 :meth:`.postgresql.ARRAY.Comparator.contains`
277 :meth:`.postgresql.ARRAY.Comparator.contained_by`, and
278 :meth:`.postgresql.ARRAY.Comparator.overlap`, e.g.::
279
280 mytable.c.data.contains([1, 2])
281
282 Indexed access is one-based by default, to match that of PostgreSQL;
283 for zero-based indexed access, set
284 :paramref:`_postgresql.ARRAY.zero_indexes`.
285
286 Additionally, the :class:`_postgresql.ARRAY`
287 type does not work directly in
288 conjunction with the :class:`.ENUM` type. For a workaround, see the
289 special type at :ref:`postgresql_array_of_enum`.
290
291 .. container:: topic
292
293 **Detecting Changes in ARRAY columns when using the ORM**
294
295 The :class:`_postgresql.ARRAY` type, when used with the SQLAlchemy ORM,
296 does not detect in-place mutations to the array. In order to detect
297 these, the :mod:`sqlalchemy.ext.mutable` extension must be used, using
298 the :class:`.MutableList` class::
299
300 from sqlalchemy.dialects.postgresql import ARRAY
301 from sqlalchemy.ext.mutable import MutableList
302
303
304 class SomeOrmClass(Base):
305 # ...
306
307 data = Column(MutableList.as_mutable(ARRAY(Integer)))
308
309 This extension will allow "in-place" changes such to the array
310 such as ``.append()`` to produce events which will be detected by the

Callers 15

test_array_column_typesFunction · 0.90
define_tablesMethod · 0.90
test_nullsnotdistinctMethod · 0.90
NodeClass · 0.90
INT2VECTORClass · 0.70
OIDVECTORClass · 0.70
pg_catalog.pyFile · 0.70
delete_pathMethod · 0.70

Calls

no outgoing calls