MCPcopy
hub / github.com/django/django / as_postgresql

Method as_postgresql

django/db/models/functions/json.py:35–62  ·  view source on GitHub ↗
(self, compiler, connection, **extra_context)

Source from the content-addressed store, hash-verified

33 )
34
35 def as_postgresql(self, compiler, connection, **extra_context):
36 # Casting source expressions is only required using JSONB_BUILD_ARRAY
37 # or when using JSON_ARRAY on PostgreSQL 16+ with server-side bindings.
38 # This is done in all cases for consistency.
39 casted_obj = self.copy()
40 casted_obj.set_source_expressions(
41 [
42 (
43 # Conditional Cast to avoid unnecessary wrapping.
44 expression
45 if isinstance(expression, Cast)
46 else Cast(expression, expression.output_field)
47 )
48 for expression in casted_obj.get_source_expressions()
49 ]
50 )
51
52 if connection.features.is_postgresql_16:
53 return casted_obj.as_native(
54 compiler, connection, returning="JSONB", **extra_context
55 )
56
57 return casted_obj.as_sql(
58 compiler,
59 connection,
60 function="JSONB_BUILD_ARRAY",
61 **extra_context,
62 )
63
64 def as_oracle(self, compiler, connection, **extra_context):
65 return self.as_native(compiler, connection, returning="CLOB", **extra_context)

Callers

nothing calls this directly

Calls 6

CastClass · 0.90
copyMethod · 0.45
as_nativeMethod · 0.45
as_sqlMethod · 0.45

Tested by

no test coverage detected