VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
ai_prompt() adds one.
With VillageSQL: Summaries in SQL
Structured summaries
For use cases where you need to extract specific fields, ask for JSON output:Summarizing multi-column content
Build richer context for the model by joining multiple fields:LEFT(body, 3000) avoids sending excessively long text to the model. Most AI models have a token limit; for very long documents, summarize the first few thousand characters or chunk the content.
Length and Style Control
Prompt phrasing controls output length and tone:
For summaries used in UI previews, specify a character limit to avoid overflow.
Model Selection
Summarization is generally well-handled by faster, cheaper models. Useclaude-haiku-4-5-20251001 or gpt-4o-mini for bulk summarization. Step up to claude-sonnet-4-5-20250929 when:
- The source text is long and complex
- You need structured JSON extraction with nuanced fields
- Accuracy of extracted facts matters more than cost
Frequently Asked Questions
How long can the source text be?
Practical limit is a few thousand words per call. AI models have token limits (typically 100K–200K tokens for current models), but very long inputs cost more and take longer. For documents over ~5000 words, summarize the first section or chunk and summarize each chunk.Can I use summaries in a full-text search index?
Yes — add a FULLTEXT index on the summary column after populating it. Summaries are often better targets for full-text search than raw content because they’re shorter and more keyword-dense.Will the same document always produce the same summary?
No — AI models are probabilistic. The same prompt can produce slightly different output on different calls. If consistency matters, generate the summary once and store it; don’t regenerate on each read.How do I summarize rows that have already been summarized?
Don’t re-summarize unless the source content changed. UseWHERE summary IS NULL to only process new or updated rows. If you need to track changes, add a summary_updated_at column and compare it to the content’s last-modified timestamp.
Troubleshooting
See also
- Running AI Models from MySQL Queries — the ai_prompt() function this guide builds on
- Sentiment Analysis on MySQL Data — another text analysis pattern with ai_prompt()
- Classifying Text in MySQL with AI — categorizing text using the same approach

