I have a table distance which is a matrix.
Holding: start , end, cost. For every start-end there is a counterpart: end-start.
The problem is that the cost for the counter parts are not equal.
I want to correct that, and am using the following SQL:
WITH subquery AS (
SELECT start, end, cost
FROM distance
)
UPDATE distance
SET cost = subquery.cost
FROM subquery
WHERE distance.start = subquery.end
AND distance.cost <> subquery.cost;
This query is now running for more then 10 hours. And I doubt if it will get me the results.
Is there a better way? I don't care if the cost comes from the start-end pair, or the end-start pair. They just need to be the same.
Using Postgres 12. The table holds about 170.000.000 records.
WHERE distance.start = subquery.end and distance.end= subquery.startI guess.startandendare keywords in SQL(see the syntax highlighting) . Better not use them as column names.