Query the zip codes with select()
The raw SQL failed in PostgreSQL because it referenced the aliased table by its full name. `select()` fixes that, matches the rest of the module, and drops the `noqa`.
This commit is contained in:
parent
f025923d25
commit
07440785ab
1 changed files with 5 additions and 13 deletions
|
|
@ -233,19 +233,11 @@ class City(meta.Base):
|
||||||
"""
|
"""
|
||||||
# First, create a color map with distinct colors for each zip code
|
# First, create a color map with distinct colors for each zip code
|
||||||
all_zip_codes = sorted(
|
all_zip_codes = sorted(
|
||||||
row[0]
|
db.session.scalars(
|
||||||
for row in db.session.execute(
|
sa.select(db.Address.zip_code)
|
||||||
sa.text(
|
.where(db.Address.city == self)
|
||||||
f"""
|
.distinct(),
|
||||||
SELECT DISTINCT
|
),
|
||||||
{pkg_config.CLEAN_SCHEMA}.addresses.zip_code
|
|
||||||
FROM
|
|
||||||
{pkg_config.CLEAN_SCHEMA}.addresses AS addresses
|
|
||||||
WHERE
|
|
||||||
{pkg_config.CLEAN_SCHEMA}.addresses.city_id = {self.id};
|
|
||||||
""", # noqa:S608
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
cmap = utils.make_random_cmap(len(all_zip_codes), bright=False)
|
cmap = utils.make_random_cmap(len(all_zip_codes), bright=False)
|
||||||
colors = {
|
colors = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue