1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

The attached patch implements the soundex difference function which

compares two strings' soundex values for similarity, from Kris Jurka.
Also mark the text_soundex() function as STRICT, to avoid crashing
on NULL input.
This commit is contained in:
Neil Conway
2005-01-26 08:04:04 +00:00
parent fd5437c78b
commit 1ac9f0e9f7
5 changed files with 56 additions and 14 deletions

View File

@ -755,3 +755,23 @@ _soundex(const char *instr, char *outstr)
++count;
}
}
PG_FUNCTION_INFO_V1(difference);
Datum
difference(PG_FUNCTION_ARGS)
{
char sndx1[SOUNDEX_LEN+1], sndx2[SOUNDEX_LEN+1];
int i, result;
_soundex(_textout(PG_GETARG_TEXT_P(0)), sndx1);
_soundex(_textout(PG_GETARG_TEXT_P(1)), sndx2);
result = 0;
for (i=0; i<SOUNDEX_LEN; i++) {
if (sndx1[i] == sndx2[i])
result++;
}
PG_RETURN_INT32(result);
}