MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / JSONB

Class JSONB

lib/sqlalchemy/dialects/postgresql/json.py:237–408  ·  view source on GitHub ↗

Represent the PostgreSQL JSONB type. The :class:`_postgresql.JSONB` type stores arbitrary JSONB format data, e.g.:: data_table = Table( "data_table", metadata, Column("id", Integer, primary_key=True), Column("data", JSONB), )

Source from the content-addressed store, hash-verified

235
236
237class JSONB(JSON[_T_JSON]):
238 """Represent the PostgreSQL JSONB type.
239
240 The :class:`_postgresql.JSONB` type stores arbitrary JSONB format data,
241 e.g.::
242
243 data_table = Table(
244 "data_table",
245 metadata,
246 Column("id", Integer, primary_key=True),
247 Column("data", JSONB),
248 )
249
250 with engine.connect() as conn:
251 conn.execute(
252 data_table.insert(), data={"key1": "value1", "key2": "value2"}
253 )
254
255 The :class:`_postgresql.JSONB` type includes all operations provided by
256 :class:`_types.JSON`, including the same behaviors for indexing
257 operations.
258 It also adds additional operators specific to JSONB, including
259 :meth:`.JSONB.Comparator.has_key`, :meth:`.JSONB.Comparator.has_all`,
260 :meth:`.JSONB.Comparator.has_any`, :meth:`.JSONB.Comparator.contains`,
261 :meth:`.JSONB.Comparator.contained_by`,
262 :meth:`.JSONB.Comparator.delete_path`,
263 :meth:`.JSONB.Comparator.path_exists` and
264 :meth:`.JSONB.Comparator.path_match`.
265
266 Like the :class:`_types.JSON` type, the :class:`_postgresql.JSONB`
267 type does not detect
268 in-place changes when used with the ORM, unless the
269 :mod:`sqlalchemy.ext.mutable` extension is used.
270
271 Custom serializers and deserializers
272 are shared with the :class:`_types.JSON` class,
273 using the ``json_serializer``
274 and ``json_deserializer`` keyword arguments. These must be specified
275 at the dialect level using :func:`_sa.create_engine`. When using
276 psycopg2, the serializers are associated with the jsonb type using
277 ``psycopg2.extras.register_default_jsonb`` on a per-connection basis,
278 in the same way that ``psycopg2.extras.register_default_json`` is used
279 to register these handlers with the json type.
280
281 .. seealso::
282
283 :class:`_types.JSON`
284
285 .. warning::
286
287 **For applications that have indexes against JSONB subscript
288 expressions**
289
290 SQLAlchemy 2.0.42 made a change in how the subscript operation for
291 :class:`.JSONB` is rendered, from ``-> 'element'`` to ``['element']``,
292 for PostgreSQL versions greater than 14. This change caused an
293 unintended side effect for indexes that were created against
294 expressions that use subscript notation, e.g.

Callers 3

test_jsonb_column_typesFunction · 0.90

Calls

no outgoing calls

Tested by 3

test_jsonb_column_typesFunction · 0.72