Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:16:09+00:00 2026-06-12T23:16:09+00:00

I have recently noticed that our product has incorrect postcode locations (lat & long

  • 0

I have recently noticed that our product has incorrect postcode locations (lat & long coordinates) for a number of “short” postcodes – i.e “AB10” rather than “ABD 1PT” etc.

The postcode database/table is used to generate pins on a Google map and I have now worked out that at some point when we merged the short postcodes to the table with full postcodes, some (around 2200) were incorrectly entered with the longitude and latitude around the wrong way.

Obviously this is a simple fix and so I decided to write a little script to take care of the incorrect values (basically swap them around).

Here is what I have:

<cfscript>

  /** Fetch the wrong postcodes data **/
  db  = "postcodes";
  sql = "
    SELECT
      postcode, longitude, latitude
    FROM
      postcodes
    WHERE
      longitude > latitude
  ";
  q    = new Query(sql = trim(sql), datasource = db);
  data = q.execute().getResult();

  if (structKeyExists(form, "execute")) {
    if (isQuery(data) && data.recordCount > 0) {
      transaction action="begin" 
      { 
        try {
          qUpdate = new Query(
            datasource = db, 
            sql = "UPDATE postcodes SET longitude = :longitude, latitude = :latitude WHERE postcode = :postcode"
          );
          for (x = 1; x <= data.recordCount; x++) {
            writeOutput("<p>" & data["postcode"][x] & "</p>");

            qUpdate.addParam(name = "longitude", value = data["latitude"][x], cfsqltype = "CF_SQL_DOUBLE");
            qUpdate.addParam(name = "latitude", value  = data["longitude"][x], cfsqltype = "CF_SQL_DOUBLE");
            qUpdate.addParam(name = "postcode", value  = data["postcode"][x], cfsqltype = "CF_SQL_VARCHAR");

            qUpdate.execute();
            qUpdate.clearParams();
          }
          transactionCommit();
        } catch (any e) {
          transactionRollback();
          writeOutput("<p>The database transaction failed, rolling back changes</p>");
          writeDump(e);
        }
      }
      writeOutput("#data.recordCount# postcodes have been updated");  
    } else {
      writeOutput("There were no incorrect postcodes found in the database");
    }
  }
</cfscript>
<cfoutput>
  <form name="update" action="" method="post">
    <input type="hidden" name="execute" value="1"/>
    <input type="submit" name="update" value="Update #val(data.recordCount)# Postcodes"/>
  </form>
</cfoutput>

<!--- <cfdump var="#data#"/> --->

The script is wrapped in a transaction as I had planned to run it on the live server however after testing the script locally it has continued to run for over an hour!

The postcode database contains almost 1.7 million records and has just three columns all correctly indexed postcode, longitude, latitude the first query returns the correct 2,200 results.

I have checked the component cache setting in ColdFusion admin to see if this was missing on my local, however it is turned on!

So my question – Why is this taking so long to execute?

We are using mysql and ACF 9.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:16:11+00:00Added an answer on June 12, 2026 at 11:16 pm

    Why do it in CF at all? Just do it all in SQL, it’ll be much faster. I don’t use mysql, but something vaguely like this:

    UPDATE postcodes 
    SET longitude = newlongitude,
    latitude = newlatitude 
    FROM (SELECT latitude AS newlongitude, longitude AS newlatitude FROM postcodes 
             WHERE longitude > latitude)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently noticed that a lot of JavaScript files on the Web start
I have a few forms that use tiny mce. I have noticed recently that
I have never come across this issue but most recently I noticed that a
I have recently started a new job and noticed that all the SQL tables
I recently released some code to our production website and I noticed that IIS
I have recently noticed that when i visit certain websites, there are usually links
I have recently noticed that nobody uses views in my company (and it's a
I have recently noticed that stack overflow for security reasons does not allow framing.
I have recently noticed that stack overflow for security reasons does not allow framing.
Recently I've noticed that when we've been doing string comparisons in our .NET code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.