First you use a split_to_array function to put your strings in to arrays (https://www.postgresql.org/docs/9.6/static/functions-string.html) and then you can compare them. Postgres has a cool function to check if one array contains another. More info on Postgres arrays here:https://www.postgresql.org/docs/9.5/static/functions-array.html
Table setup:
CREATE TABLE stringchecks
(
id serial,
name varchar(100)
);
INSERT INTO stringchecks (name) VALUES ('This is a test sentence');
INSERT INTO stringchecks (name) VALUES ('is a sentence TeST');
INSERT INTO stringchecks (name) VALUES ('This a IS test sentence');
INSERT INTO stringchecks (name) VALUES ('iS a tEst sentence tHis');
INSERT INTO stringchecks (name) VALUES ('This a test sentence is');
Checking for matches you have two options. You can use regexp_split_to_array:
SELECT
id,
name,
regexp_split_to_array(lower(name), E'\\s+') @>
regexp_split_to_array(lower('is a sentence test'), E'\\s+')
FROM stringchecks;
Or you can use string_to_array:
SELECT
id,
name,
string_to_array(lower(name), ' ') @>
string_to_array(lower('is a sentence test'), ' ')
FROM stringchecks;
In this case because it's a simple delimiter it will be faster to use string_to_array. http://www.postgresonline.com/journal/archives/370-regexp_split_to_table-and-string_to_array-unnest-performance.html
CREATE TABLEstatement). Overview of available tools: dba.stackexchange.com/questions/10694/…