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:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user