简体   繁体   中英

Conditional joining in Postgres using levenshtein

I have two tables lets say Table A and Table B...

I want to query these two tables so that I can check to see if two columns in the tables say col1 and col2 are similar and show them.

Something like:

SELECT A.col1, B.col2  
FROM A INNER JOIN B 
ON LEVENSHTEIN(A.col1, B.col2) < 2;

Ultimately I want to also get rid of all the white spaces within and just look at the characters within the columns so

if col1 values where {good, bad,} and col2 had {good,bad}

I would like those to be matches

Does this work?

SELECT A.col1, B.col2  
FROM A INNER JOIN
     B 
     ON LEVENSHTEIN(replace(A.col1, ' ', ''), replace(B.col2, ' ', '')) < 2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM