Remove stop words in a string with PostgreSQL


SELECT 
		string_agg(word, ' ') 
	FROM 
		(SELECT UNNEST(regexp_split_to_array('this is a test of the 123 stop word system 1-800-', E'\\s+')) AS "word") AS words 
	WHERE 
		word NOT IN ('a', 'and', 'is', 'of', 'the', 'this') 
		AND word !~ '^[-0-9]*$'

Tags:  postgresql

Share: