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

  • SEARCH
  • Home
  • 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 1108819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:08:29+00:00 2026-05-17T02:08:29+00:00

Background To replace invalid zip codes. Sample Data Consider the following data set: Typo

  • 0

Background

To replace invalid zip codes.

Sample Data

Consider the following data set:

 Typo  | City       | ST | Zip5
-------+------------+----+------
 33967 | Fort Myers | FL | 33902
 33967 | Fort Myers | FL | 33965
 33967 | Fort Myers | FL | 33911
 33967 | Fort Myers | FL | 33901
 33967 | Fort Myers | FL | 33907
 33967 | Fort Myers | FL | 33994
 34115 |Marco Island| FL | 34145
 34115 |Marco Island| FL | 34146
 86405 |  Kingman   | FL | 86404
 86405 |  Kingman   | FL | 86406

33967 closely matches 33965, although 33907 could also be correct. (In this case, 33967 is a valid zip code, but not in our zip code database.)

34115 closely matches is 34145 (off by one digit, with a difference of 3 for that digit).

86405 closely matches both.

Sometimes digits are simply reversed (e.g,. 89 instead of 98).

Question

How would you write a SQL statement that finds the “minimum distance” between multiple numbers that have the same number of digits, returning at most one result no matter what?

Ideas

  • Subtract the digits.
  • Use LIMIT 1.

Conditions

PostgreSQL 8.3

  • 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-05-17T02:08:30+00:00Added an answer on May 17, 2026 at 2:08 am

    This sounds like a case for Levenshtein distance.

    The Levenshtein distance between two
    strings is defined as the minimum
    number of edits needed to transform
    one string into the other, with the
    allowable edit operations being
    insertion, deletion, or substitution
    of a single character.

    It looks like PostgreSQL has it built-in:

    test=# SELECT levenshtein('GUMBO', 'GAMBOL');
     levenshtein
    -------------
               2
    (1 row)
    

    http://www.postgresql.org/docs/8.3/static/fuzzystrmatch.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use GreaseMonkey to replace the background image of a DIV on
Background: We're building an application that allows our customers to supply data in a
In css you may normally set both a background-image, and a background-color, and the
Background We're using Alfresco to replace SharePoint. The primary use is document sharing and
I have a UIImage with white background. I would like replace the white background/pixels
I'm trying to replace the links on my app with a button background. However
Background I've been contracted to analyze an existing Data Provider and I know the
I'm building a Firefox Extension that, among other things, needs to replace body background
I am using a background image to replace the text of a link using
How fast can I replace characters in a string? So the background on this

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.