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

Class ARRAY

lib/sqlalchemy/sql/sqltypes.py:2973–3417  ·  view source on GitHub ↗

Represent a SQL Array type. .. note:: This type serves as the basis for all ARRAY operations. However, currently **only the PostgreSQL backend has support for SQL arrays in SQLAlchemy**. It is recommended to use the PostgreSQL-specific :class:`sqlalchemy.dialects.postgresq

Source from the content-addressed store, hash-verified

2971
2972
2973class ARRAY(
2974 SchemaEventTarget, Indexable, Concatenable, TypeEngine[Sequence[_T]]
2975):
2976 """Represent a SQL Array type.
2977
2978 .. note:: This type serves as the basis for all ARRAY operations.
2979 However, currently **only the PostgreSQL backend has support for SQL
2980 arrays in SQLAlchemy**. It is recommended to use the PostgreSQL-specific
2981 :class:`sqlalchemy.dialects.postgresql.ARRAY` type directly when using
2982 ARRAY types with PostgreSQL, as it provides additional operators
2983 specific to that backend.
2984
2985 :class:`_types.ARRAY` is part of the Core in support of various SQL
2986 standard functions such as :class:`_functions.array_agg`
2987 which explicitly involve
2988 arrays; however, with the exception of the PostgreSQL backend and possibly
2989 some third-party dialects, no other SQLAlchemy built-in dialect has support
2990 for this type.
2991
2992 An :class:`_types.ARRAY` type is constructed given the "type"
2993 of element::
2994
2995 mytable = Table("mytable", metadata, Column("data", ARRAY(Integer)))
2996
2997 The above type represents an N-dimensional array,
2998 meaning a supporting backend such as PostgreSQL will interpret values
2999 with any number of dimensions automatically. To produce an INSERT
3000 construct that passes in a 1-dimensional array of integers::
3001
3002 connection.execute(mytable.insert(), {"data": [1, 2, 3]})
3003
3004 The :class:`_types.ARRAY` type can be constructed given a fixed number
3005 of dimensions::
3006
3007 mytable = Table(
3008 "mytable", metadata, Column("data", ARRAY(Integer, dimensions=2))
3009 )
3010
3011 Sending a number of dimensions is optional, but recommended if the
3012 datatype is to represent arrays of more than one dimension. This number
3013 is used:
3014
3015 * When emitting the type declaration itself to the database, e.g.
3016 ``INTEGER[][]``
3017
3018 * When translating Python values to database values, and vice versa, e.g.
3019 an ARRAY of :class:`.Unicode` objects uses this number to efficiently
3020 access the string values inside of array structures without resorting
3021 to per-row type inspection
3022
3023 * When used with the Python ``getitem`` accessor, the number of dimensions
3024 serves to define the kind of type that the ``[]`` operator should
3025 return, e.g. for an ARRAY of INTEGER with two dimensions::
3026
3027 >>> expr = table.c.column[5] # returns ARRAY(Integer, dimensions=1)
3028 >>> expr = expr[6] # returns Integer
3029
3030 For 1-dimensional arrays, an :class:`_types.ARRAY` instance with no

Calls

no outgoing calls