TutorialsAIPostgreSQLSQL

Neon Database: Natural Language Queries for Serverless PostgreSQL

Neon has become one of the fastest-growing PostgreSQL options in the developer ecosystem, and for good reason. Serverless branching, instant provisioning, an...

James Okonkwo· Developer AdvocateApril 9, 20268 min read

Neon has become one of the fastest-growing PostgreSQL options in the developer ecosystem, and for good reason. Serverless branching, instant provisioning, and scale-to-zero pricing make it a natural choice for SaaS applications, side projects, and modern development workflows. But Neon's adoption is primarily developer-driven the same application engineers who are comfortable writing SQL.

That creates an obvious gap. Once a Neon-powered application is running in production, the product managers, analysts, and operations folks who need insights from it are largely locked out. They can't write SQL, they don't have database credentials, and they're not going to spin up a Neon branch to run exploratory queries.

This guide covers how to query a Neon database in plain English getting the data you need without writing SQL and how to set up automated dashboards and alerts on top of Neon's serverless infrastructure.

-

What Makes Neon Different (and Why It Matters for Analytics)

Before getting into the query layer, it's worth understanding a few Neon-specific characteristics that shape how you approach analytics on top of it.

Serverless with connection pooling: Neon uses connection poolers (PgBouncer by default) to handle the serverless connection model. When connecting with tools, use the pooled connection string (the one with -pooler in the hostname) for transactional queries and the direct connection string for longer-running analytical queries.

Branching: Neon's branching feature lets you create database branches isolated copies of your database at a point in time for development and testing. For analytics purposes, you can run heavy analytical queries against a branch without touching production, though for most teams this adds operational complexity without enough benefit to justify it.

Scale to zero: Neon instances can scale to zero when idle, which means the first connection after a cold start has a brief delay (usually under 500ms). This is generally fine for interactive queries but worth being aware of for automated dashboards.

Neon is fully PostgreSQL-compatible, which means every SQL technique, extension, and tool that works with PostgreSQL works with Neon. Natural language query tools that support PostgreSQL support Neon without any modification.

-

Connecting Neon to an AI Query Interface

To query Neon in plain English, you need a tool that sits between the natural language input and the database. The flow looks like this:

User question in plain English
       ↓
AI layer (understands your schema, translates to SQL)
       ↓
Neon PostgreSQL database
       ↓
Results returned as table or chart

AI for Database supports this connection natively. Here's how to set it up:

  • Get your Neon connection string from the Neon dashboard under Connection Details. Choose the pooled connection for most use cases.
  • It looks like:

       postgresql://username:password@ep-quiet-flower-123456-pooler.us-east-2.aws.neon.tech/dbname?sslmode=require
  • Connect in AI for Database: Add a new database connection, paste the connection string, and the tool will introspect your schema automatically reading table names, column names, relationships, and data types.
  • Start asking questions: Once connected, you can type queries like:
  • "How many new users signed up in the last 7 days?"
  • "Show me revenue by plan type for this month"
  • "Which customers haven't logged in for 30 days?"
  • The AI translates these to PostgreSQL SQL, runs them against your Neon database, and returns results. You can see the generated SQL alongside the results so you understand exactly what ran.

    -

    Practical Query Examples on a SaaS Database

    Let's walk through some realistic Neon database queries that non-technical team members regularly need.

    Product team: user activation funnel

    A product manager wants to know where users drop off between signup and first meaningful action. In plain English: "Show me the percentage of users who completed each step of the onboarding flow last month."

    The generated SQL on a typical SaaS schema might look like:

    WITH cohort AS (
        SELECT id AS user_id
        FROM users
        WHERE created_at >= date_trunc('month', current_date - interval '1 month')
          AND created_at < date_trunc('month', current_date)
    ),
    steps AS (
        SELECT
            (SELECT COUNT(*) FROM cohort) AS signed_up,
            (SELECT COUNT(DISTINCT user_id) FROM events e
             JOIN cohort c ON e.user_id = c.user_id
             WHERE e.event_type = 'email_verified') AS verified_email,
            (SELECT COUNT(DISTINCT user_id) FROM events e
             JOIN cohort c ON e.user_id = c.user_id
             WHERE e.event_type = 'first_connection') AS connected_db,
            (SELECT COUNT(DISTINCT user_id) FROM events e
             JOIN cohort c ON e.user_id = c.user_id
             WHERE e.event_type = 'first_query') AS ran_first_query
    )
    SELECT
        signed_up,
        verified_email,
        ROUND(100.0 * verified_email / signed_up, 1) AS verified_pct,
        connected_db,
        ROUND(100.0 * connected_db / signed_up, 1) AS connected_pct,
        ran_first_query,
        ROUND(100.0 * ran_first_query / signed_up, 1) AS activated_pct
    FROM steps;

    A product manager doesn't need to write this. They type their question, get a table back, and the SQL is visible if they want to verify it.

    Revenue operations: MRR breakdown

    A RevOps analyst asks: "What's our MRR by plan for each of the last 6 months?"

    SELECT
        date_trunc('month', s.current_period_start) AS month,
        p.name AS plan_name,
        COUNT(*) AS subscribers,
        SUM(p.monthly_price) AS mrr
    FROM subscriptions s
    JOIN plans p ON s.plan_id = p.id
    WHERE s.status = 'active'
      AND s.current_period_start >= now() - interval '6 months'
    GROUP BY 1, 2
    ORDER BY 1 DESC, 3 DESC;

    Customer support: investigating a specific account

    A support agent needs context before a call: "Show me everything that happened with account ID 4821 in the last 14 days."

    SELECT
        e.created_at,
        e.event_type,
        e.metadata
    FROM events e
    WHERE e.user_id IN (
        SELECT id FROM users WHERE account_id = 4821
    )
    AND e.created_at > now() - interval '14 days'
    ORDER BY e.created_at DESC
    LIMIT 50;

    These are queries that would take a developer 10–20 minutes to write and send back. With a natural language layer, the support agent gets the answer in seconds.

    -

    Building Self-Refreshing Dashboards on Neon

    One of the highest-value things you can do on top of a Neon database is build dashboards that update automatically rather than requiring someone to manually re-run queries.

    A typical example: a startup's weekly review needs to cover signups, activation rate, active subscriptions, and any revenue changes. Pulling this manually every Monday morning from the database is tedious and error-prone.

    With AI for Database, you can build a dashboard by defining each panel as a plain-English question. The tool generates the SQL, runs it, renders the chart, and refreshes on a schedule you configure. The dashboard lives at a shareable URL no login required for read-only consumers.

    For a Neon database specifically, there are two things to keep in mind:

  • Use the pooled connection string for the dashboard connection to avoid connection exhaustion on Neon's serverless infrastructure.
  • Set the refresh interval to something reasonable for your use case. Neon's scale-to-zero means the first query after idle has a short cold start; refreshing every 5 minutes keeps the instance warm without hitting scale-to-zero.
  • -

    Neon-Specific SQL Features Worth Knowing

    Neon supports all standard PostgreSQL features, plus a few things worth using in analytics queries.

    Logical replication for read replicas

    Neon supports read replicas via logical replication. For analytical workloads, you can create a read replica and point your AI query tool at it keeping heavy analytical queries off your primary instance entirely.

    Time travel queries with Neon branches

    Neon's branching lets you create a point-in-time copy of your database. This is useful for answering "what did our data look like last Tuesday?" questions without maintaining a separate snapshot infrastructure:

  • Create a branch at the desired timestamp in the Neon dashboard
  • Connect to the branch using its connection string
  • Run your historical analysis
  • Delete the branch when done
  • For regulatory or audit purposes, a Neon branch is a fast way to reconstruct the database state at any point within your history retention window.

    Using pg_stat_statements for query performance

    The pg_stat_statements extension is available on Neon and gives you a query-level performance view without needing external monitoring tools:

     Enable the extension (once per database)
    CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
    
     Top 10 slowest queries by total execution time
    SELECT
        LEFT(query, 100) AS query_preview,
        calls,
        ROUND((mean_exec_time)::numeric, 2) AS avg_ms,
        ROUND((total_exec_time)::numeric, 2) AS total_ms,
        rows
    FROM pg_stat_statements
    ORDER BY total_exec_time DESC
    LIMIT 10;

    You can connect this view directly to AI for Database and ask natural language questions about query performance: "Which queries are hitting the database most often?" or "What's the slowest query in the last hour?"

    -

    Setting Up Automated Alerts on Neon

    Beyond dashboards, you can configure automated monitors that watch your Neon database and trigger actions when conditions are met without writing any cron jobs or polling code.

    Some examples that make sense for a Neon-powered SaaS:

    New user growth alert: Send a Slack message when daily signups drop more than 20% compared to the 7-day average.

    WITH daily_avg AS (
        SELECT
            AVG(daily_count) AS avg_signups
        FROM (
            SELECT DATE(created_at), COUNT(*) AS daily_count
            FROM users
            WHERE created_at >= now() - interval '7 days'
            GROUP BY 1
        ) sub
    ),
    today AS (
        SELECT COUNT(*) AS today_count
        FROM users
        WHERE DATE(created_at) = CURRENT_DATE
    )
    SELECT
        today.today_count,
        daily_avg.avg_signups,
        ROUND(100.0 * (today.today_count - daily_avg.avg_signups) / daily_avg.avg_signups, 1) AS pct_change
    FROM today, daily_avg
    WHERE today.today_count < daily_avg.avg_signups * 0.8;

    If this query returns a row, the alert fires. AI for Database handles the scheduling, runs the query, and sends the notification you define the condition and the action.

    -

    Ready to try AI for Database?

    Query your database in plain English. No SQL required. Start free today.