SELECT 'form' AS component, 'Enter your text:' AS title; SELECT 'Text' AS name, 'textarea' AS type, :Text AS value; WITH RECURSIVE letters(n, l) AS ( SELECT 0, '' UNION ALL SELECT n+1, SUBSTRING(:Text, n+1, 1) FROM letters WHERE n < LENGTH(:Text) ), is_word(n, l, is_word) AS ( SELECT n, l, l BETWEEN 'a' AND 'z' OR l BETWEEN 'A' AND 'Z' FROM letters ), word_beginnings(is_beginning) AS ( SELECT is_word AND NOT LAG(is_word) OVER (ORDER BY n) FROM is_word ) SELECT 'text' AS component, 'Word count: ' || SUM(is_beginning::int) AS contents FROM word_beginnings;