# Natural Language Postgres Guide

> Build a Next.js app to query PostgreSQL using natural language

An official tutorial from Vercel demonstrating how to build a natural language interface for PostgreSQL databases using the Vercel AI SDK and Next.js. It explains how to generate structured SQL queries, break down query clauses into plain-English explanations, and display results in charts and tables. It serves as a practical starter pattern for developer tooling and AI-powered internal analytics dashboards.

Website: https://ai-sdk.dev/cookbook/guides/natural-language-postgres

## What it is for

- Build natural language database querying features into web applications
- Explain complex generated SQL queries clause-by-clause for non-technical users
- Visualize dynamic database query results with shadcn/ui and Recharts

## Features

- Structured SQL generation using Vercel AI SDK and Zod schema validation
- Prompt patterns tailored for PostgreSQL schema retrieval and edge case handling
- Query explanation generation split into clause-by-clause sections
- Data visualization using shadcn/ui components and Recharts
- Server Actions architecture for secure LLM execution in Next.js App Router

## Pricing

Free documentation and open-source starter code

## Details

- Type: Article or course
- Category: [Development](https://xiry.app/topics/development.md)
- Open source: yes
- Platforms: Web
- For: Next.js and full-stack developers building AI-assisted database tools
- Alternative to: Text-to-SQL documentation and tutorials
- Tags: postgresql, ai sdk, nextjs, sql, react, text to sql

## Why it was saved

- [@nicoalbanese10, 6 November 2024](https://x.com/nicoalbanese10/status/1854264739356110935): Tutorial for the pattern demoed in the video; reusable for any database-query product.

## Related

- [Natural Language Postgres](https://xiry.app/resources/natural-language-postgres): Query a Postgres database with natural language and visualize results. (Web app, Open source)
- [shadcn/ui](https://xiry.app/resources/shadcn-ui-1902): Copy-paste React UI components built with Tailwind CSS and Radix primitives. (Website, Open source)
- [json-render](https://xiry.app/resources/json-render): Generative UI framework rendering LLM JSON streams into predefined components safely (Web app, Open source)
- [Efferd](https://xiry.app/resources/efferd): Pre-built, responsive shadcn/ui blocks and layouts for React applications (Web app, Freemium)
- [Spell UI](https://xiry.app/resources/spell-ui): Refined, copy-paste React and Tailwind CSS components with micro-interactions (GitHub repo, Open source)
- [Above-the-Fold Deferred Rendering Pattern](https://xiry.app/resources/above-the-fold-deferred-rendering-pattern): Performance pattern for deferring below-the-fold components to accelerate perceived page load. (Tip, Free)

Updated 10 October 2026. Page: https://xiry.app/resources/natural-language-postgres-guide

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
