mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-28 11:55:03 +03:00 
			
		
		
		
	fuzzystrmatch's difference() function assumes that _soundex() always initializes its output buffer fully. This was not so for the case of a string containing no alphabetic characters, resulting in unstable output and Valgrind complaints. Fix by using memset() to fill the whole buffer in the early-exit case. Also make some cosmetic improvements (I didn't care for the random switches between "instr[0]" and "*instr" notation). Report and diagnosis by Alexander Lakhin (bug #17935). Back-patch to all supported branches. Discussion: https://postgr.es/m/17935-b99316aa79c18513@postgresql.org
		
			
				
	
	
		
			68 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			SQL
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			SQL
		
	
	
	
	
	
| CREATE EXTENSION fuzzystrmatch;
 | |
| 
 | |
| 
 | |
| SELECT soundex('hello world!');
 | |
| 
 | |
| SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
 | |
| SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew');
 | |
| SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
 | |
| SELECT soundex(''), difference('', '');
 | |
| 
 | |
| 
 | |
| SELECT levenshtein('GUMBO', 'GAMBOL');
 | |
| SELECT levenshtein('GUMBO', 'GAMBOL', 2, 1, 1);
 | |
| SELECT levenshtein_less_equal('extensive', 'exhaustive', 2);
 | |
| SELECT levenshtein_less_equal('extensive', 'exhaustive', 4);
 | |
| 
 | |
| 
 | |
| SELECT metaphone('GUMBO', 4);
 | |
| 
 | |
| 
 | |
| SELECT dmetaphone('gumbo');
 | |
| SELECT dmetaphone_alt('gumbo');
 | |
| 
 | |
| -- Wovels
 | |
| SELECT daitch_mokotoff('Augsburg');
 | |
| SELECT daitch_mokotoff('Breuer');
 | |
| SELECT daitch_mokotoff('Freud');
 | |
| 
 | |
| -- The letter "H"
 | |
| SELECT daitch_mokotoff('Halberstadt');
 | |
| SELECT daitch_mokotoff('Mannheim');
 | |
| 
 | |
| -- Adjacent sounds
 | |
| SELECT daitch_mokotoff('Chernowitz');
 | |
| 
 | |
| -- Adjacent letters with identical adjacent code digits
 | |
| SELECT daitch_mokotoff('Cherkassy');
 | |
| SELECT daitch_mokotoff('Kleinman');
 | |
| 
 | |
| -- More than one word
 | |
| SELECT daitch_mokotoff('Nowy Targ');
 | |
| 
 | |
| -- Padded with "0"
 | |
| SELECT daitch_mokotoff('Berlin');
 | |
| 
 | |
| -- Other examples from https://www.avotaynu.com/soundex.htm
 | |
| SELECT daitch_mokotoff('Ceniow');
 | |
| SELECT daitch_mokotoff('Tsenyuv');
 | |
| SELECT daitch_mokotoff('Holubica');
 | |
| SELECT daitch_mokotoff('Golubitsa');
 | |
| SELECT daitch_mokotoff('Przemysl');
 | |
| SELECT daitch_mokotoff('Pshemeshil');
 | |
| SELECT daitch_mokotoff('Rosochowaciec');
 | |
| SELECT daitch_mokotoff('Rosokhovatsets');
 | |
| 
 | |
| -- Ignored characters
 | |
| SELECT daitch_mokotoff('''OBrien');
 | |
| SELECT daitch_mokotoff('O''Brien');
 | |
| 
 | |
| -- "Difficult" cases, likely to cause trouble for other implementations.
 | |
| SELECT daitch_mokotoff('CJC');
 | |
| SELECT daitch_mokotoff('BESST');
 | |
| SELECT daitch_mokotoff('BOUEY');
 | |
| SELECT daitch_mokotoff('HANNMANN');
 | |
| SELECT daitch_mokotoff('MCCOYJR');
 | |
| SELECT daitch_mokotoff('ACCURSO');
 | |
| SELECT daitch_mokotoff('BIERSCHBACH');
 |