Discord wants to compare two messages from a channel and identify words that appear in only one of them. Write a PostgreSQL query that tokenizes the selected messages, removes words shared by both messages, and returns each remaining word once.
Requirements
- Read the two target messages from
discord_messages, joining discord_channels to verify they belong to the requested Discord channel.
- Split message content into words using PostgreSQL string functions and preserve each word's message order.
- Treat exact spellings as separate tokens when determining whether a word is shared. After identifying words unique to one message, deduplicate case-insensitively while preserving the first spelling encountered.
- Return the words in their first-occurrence order across the two messages.
Output details
- Select channel
10 and messages 101 and 102.
- Exclude rows whose
content is NULL.
- Split
content on one or more whitespace characters.
- Return a single column named
word.
- Order results by ascending
message_id, then ascending token position.