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

Method _columns_query

lib/sqlalchemy/dialects/postgresql/base.py:4129–4292  ·  view source on GitHub ↗
(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 # NOTE: the query with the default and identity options scalar
4131 # subquery is faster than trying to use outer joins for them
4132 generated = (
4133 pg_catalog.pg_attribute.c.attgenerated.label("generated")
4134 if self.server_version_info >= (12,)
4135 else sql.null().label("generated")
4136 )
4137 if self.server_version_info >= (10,):
4138 # join lateral performs worse (~2x slower) than a scalar_subquery
4139 # also the subquery can be run only if the column is an identity
4140 identity = sql.case(
4141 ( # attidentity != '' is required or it will reflect also
4142 # serial columns as identity.
4143 pg_catalog.pg_attribute.c.attidentity != "",
4144 select(
4145 sql.func.json_build_object(
4146 "always",
4147 pg_catalog.pg_attribute.c.attidentity == "a",
4148 "start",
4149 pg_catalog.pg_sequence.c.seqstart,
4150 "increment",
4151 pg_catalog.pg_sequence.c.seqincrement,
4152 "minvalue",
4153 pg_catalog.pg_sequence.c.seqmin,
4154 "maxvalue",
4155 pg_catalog.pg_sequence.c.seqmax,
4156 "cache",
4157 pg_catalog.pg_sequence.c.seqcache,
4158 "cycle",
4159 pg_catalog.pg_sequence.c.seqcycle,
4160 type_=sqltypes.JSON(),
4161 )
4162 )
4163 .select_from(pg_catalog.pg_sequence)
4164 .where(
4165 # not needed but pg seems to like it
4166 pg_catalog.pg_attribute.c.attidentity != "",
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