oskar
12/30/2021, 4:06 PMexecute
and captures
? Would I need to escape something?
SQL
CREATE FUNCTION parse_tokens(content text, prefix text)
RETURNS text[] AS $$
DECLARE
regex text;
matches text;
subquery text;
captures text;
tokens text[];
BEGIN
regex := prefix || '(\S+)';
matches := 'regexp_matches($1, $2, $3) as captures';
subquery := '(SELECT ' || matches || ' ORDER BY captures) as matches';
captures := 'array_agg(matches.captures[1])';
EXECUTE 'SELECT ' || captures || ' FROM ' || subquery
INTO tokens
USING LOWER(content), regex, 'g';
IF tokens IS NULL THEN
tokens = '{}';
END IF;
RETURN tokens;
END;
$$ LANGUAGE plpgsql STABLE;
ktosiek
12/30/2021, 8:06 PMprefix
parameterktosiek
12/30/2021, 8:07 PMktosiek
12/30/2021, 8:08 PMprefix
it should be fine (maybe except for "regexp DoS")oskar
12/31/2021, 10:29 AM