Commit 7afb795e authored by Danijel Schorlemmer's avatar Danijel Schorlemmer
Browse files

Simplified the SQL query and optimized for processing speed

parent bd4bfec8
Pipeline #37870 passed with stage
in 1 minute and 31 seconds
......@@ -1065,16 +1065,13 @@ class JapanDatabase(SpatialiteDatabase):
# Calculate the population_density with the boundary area from Districts table
# and update the PopulationDistribution table
sql_statement = (
"WITH updates(ID, population_density) "
"AS (SELECT PopulationDistribution.district_id, PopulationDistribution.total/ "
"District.area_size "
"FROM PopulationDistribution "
"INNER JOIN District ON District.id = PopulationDistribution.district_id) "
)
sql_statement += (
"UPDATE PopulationDistribution "
"SET population_density = (SELECT population_density FROM updates "
"WHERE PopulationDistribution.district_id = ID)"
"SET population_density = Q.density FROM "
"(SELECT PopulationDistribution.total/District.area_size AS density, "
"PopulationDistribution.district_id AS id "
"FROM PopulationDistribution INNER JOIN District "
"ON District.id = PopulationDistribution.district_id) AS Q "
"WHERE PopulationDistribution.district_id = Q.id"
)
logger.debug(sql_statement)
self.cursor.execute(sql_statement)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment