Easy to Read Solution
Intuition
The goal is to transform each content string so that every word is properly capitalized—even when words are hyphenated.
The challenge lies in handling
## Intuition
- The goal is to transform each content string so that every word is properly capitalized—even when words are hyphenated. 
- The challenge lies in handling hyphenated words where both parts need to be capitalized independently. 
- The idea is to break the text into words, further split any word containing a hyphen, apply standard capitalization to each segment, and then reconstruct the text.
# Approach
- Splitting the Content:
Use the string_to_array function to split the original text into individual words based on spaces.

Processing Each Word:

    For each word, check if it contains a hyphen (LIKE '%-%').

    If it does, split the word further using string_to_array(word, '-'), apply INITCAP to each sub-word to capitalize it properly, and rejoin the parts using ARRAY_TO_STRING with a hyphen.

    If it does not contain a hyphen, simply apply INITCAP to the word.

- Reconstructing the Text:
Use STRING_AGG to join the processed words back together into a full sentence, preserving spaces.

- *Italic*Output:
Return the original text alongside the converted text, ensuring that all words now have the proper capitalization as required.
![upvote.jpg](https://assets.leetcode.com/users/images/3de5fe9f-1281-4f39-a074-05f904fa07d0_1743617720.658321.jpeg)



# Code
```postgresql []
-- Use a CTE to split the content into words, format each word, and then reassemble the text.
WITH formatted_content AS (
    SELECT 
        content_id,
        content_text AS original_text,
        -- Reassemble the formatted words into a single string
        STRING_AGG(
            CASE 
                -- Check if the word contains a hyphen
                WHEN word LIKE '%-%' THEN
                    -- For hyphenated words, split by '-', capitalize each part with INITCAP, then join them back with '-'
                    ARRAY_TO_STRING(
                        ARRAY(
                            SELECT INITCAP(part) 
                            FROM UNNEST(string_to_array(word, '-')) AS part
                        ), 
                        '-'
                    )
                ELSE
                    -- For non-hyphenated words, just apply INITCAP to capitalize the first letter and lower the rest.
                    INITCAP(word)
            END, 
            ' '   -- Rejoin the words with a space separator
        ) AS converted_text
    FROM (
        -- Split the content_text into individual words by spaces
        SELECT 
            content_id,
            content_text,
            UNNEST(string_to_array(content_text, ' ')) AS word
        FROM user_content
    ) AS words
    GROUP BY content_id, content_text
)
-- Return both the original and the converted text for each content_id, ordered by content_id.
SELECT content_id, original_text, converted_text
FROM formatted_content
ORDER BY content_id;

['PostgreSQL']