MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _columns_query

Method _columns_query

lib/sqlalchemy/dialects/postgresql/base.py:4129–4292  ·  lib/sqlalchemy/dialects/postgresql/base.py::PGDialect._columns_query
(self, schema, has_filter_names, scope, kind)

Source from the content-addressed store, hash-verified

4127
4128 @lru_cache()
4129 def _columns_query(self, schema, has_filter_names, scope, kind):
4130 class="cm"># NOTE: the query with the default and identity options scalar
4131 class="cm"># subquery is faster than trying to use outer joins for them
4132 generated = (
4133 pg_catalog.pg_attribute.c.attgenerated.label(class="st">"generated")
4134 if self.server_version_info >= (12,)
4135 else sql.null().label(class="st">"generated")
4136 )
4137 if self.server_version_info >= (10,):
4138 class="cm"># join lateral performs worse (~2x slower) than a scalar_subquery
4139 class="cm"># also the subquery can be run only if the column is an identity
4140 identity = sql.case(
4141 ( class="cm"># attidentity != class="st">'' is required or it will reflect also
4142 class="cm"># serial columns as identity.
4143 pg_catalog.pg_attribute.c.attidentity != class="st">"",
4144 select(
4145 sql.func.json_build_object(
4146 class="st">"always",
4147 pg_catalog.pg_attribute.c.attidentity == class="st">"a",
4148 class="st">"start",
4149 pg_catalog.pg_sequence.c.seqstart,
4150 class="st">"increment",
4151 pg_catalog.pg_sequence.c.seqincrement,
4152 class="st">"minvalue",
4153 pg_catalog.pg_sequence.c.seqmin,
4154 class="st">"maxvalue",
4155 pg_catalog.pg_sequence.c.seqmax,
4156 class="st">"cache",
4157 pg_catalog.pg_sequence.c.seqcache,
4158 class="st">"cycle",
4159 pg_catalog.pg_sequence.c.seqcycle,
4160 type_=sqltypes.JSON(),
4161 )
4162 )
4163 .select_from(pg_catalog.pg_sequence)
4164 .where(
4165 class="cm"># not needed but pg seems to like it
4166 pg_catalog.pg_attribute.c.attidentity != class="st">"",
4167 pg_catalog.pg_sequence.c.seqrelid
4168 == sql.cast(
4169 sql.cast(
4170 pg_catalog.pg_get_serial_sequence(
4171 sql.cast(
4172 sql.cast(
4173 pg_catalog.pg_attribute.c.attrelid,
4174 REGCLASS,
4175 ),
4176 TEXT,
4177 ),
4178 pg_catalog.pg_attribute.c.attname,
4179 ),
4180 REGCLASS,
4181 ),
4182 OID,
4183 ),
4184 )
4185 .correlate(pg_catalog.pg_attribute)
4186 .scalar_subquery(),

Callers 2

get_multi_columnsMethod · 0.95
init_classMethod · 0.95

Calls 15

_kind_to_relkindsMethod · 0.95
selectFunction · 0.90
bindparamFunction · 0.85
format_typeMethod · 0.80
labelMethod · 0.45
scalar_subqueryMethod · 0.45
correlateMethod · 0.45
whereMethod · 0.45
select_fromMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected