PostgreSQL integration

Ask your PostgreSQL database in plain English.

Connect a PostgreSQL database to InsightLab and ask business questions in plain language. InsightLab builds the query and returns the result as a table or chart, so the people closest to the question don’t have to wait for someone who can write SQL.

Example questions

From a business question to a PostgreSQL query.

A question asked of PostgreSQL has to end up as PostgreSQL SQL. These four pairs show what that looks like for questions a sales or finance lead might ask.

Illustrative examples. The SQL below was written by hand against a sample schema (orders and customers) to show the PostgreSQL dialect. It is not output captured from InsightLab, and your own tables and columns will differ.

  1. “How has monthly revenue trended over the last 12 months?”

    date_trunc rounds each timestamp down to the first of its month, the standard way to group by month in PostgreSQL. The interval arithmetic keeps the window to twelve whole months.

    Illustrative PostgreSQL SQL on a sample schema
    SELECT date_trunc('month', ordered_at) AS month,
           sum(total_amount)               AS revenue
    FROM orders
    WHERE status = 'paid'
      AND ordered_at >= date_trunc('month', now()) - interval '11 months'
    GROUP BY 1
    ORDER BY 1;
  2. “What share of last quarter’s orders were refunded, by sales channel?”

    The FILTER clause counts only the rows that match a condition, so all orders and refunded orders are counted in one pass, without a CASE expression.

    Illustrative PostgreSQL SQL on a sample schema
    SELECT channel,
           count(*)                                    AS orders,
           count(*) FILTER (WHERE status = 'refunded') AS refunded,
           round(100.0 * count(*) FILTER (WHERE status = 'refunded')
                 / count(*), 1)                        AS refund_rate_pct
    FROM orders
    WHERE ordered_at >= date_trunc('quarter', now()) - interval '3 months'
      AND ordered_at <  date_trunc('quarter', now())
    GROUP BY channel
    ORDER BY refund_rate_pct DESC;
  3. “Who are our top 10 customers by revenue this year, and when did each last order?”

    A join, two aggregates and a LIMIT. The ::date cast is PostgreSQL shorthand for trimming a timestamp down to a date.

    Illustrative PostgreSQL SQL on a sample schema
    SELECT c.name,
           sum(o.total_amount)     AS revenue,
           max(o.ordered_at)::date AS last_order
    FROM customers c
    JOIN orders o ON o.customer_id = c.id
    WHERE o.status = 'paid'
      AND o.ordered_at >= date_trunc('year', now())
    GROUP BY c.id, c.name
    ORDER BY revenue DESC
    LIMIT 10;
  4. “What was the most recent order from each customer in Germany?”

    DISTINCT ON is a PostgreSQL extension. It keeps the first row for each customer after sorting, which is a compact way to answer “latest record per group” questions.

    Illustrative PostgreSQL SQL on a sample schema
    SELECT DISTINCT ON (o.customer_id)
           c.name,
           o.ordered_at,
           o.total_amount,
           o.status
    FROM orders o
    JOIN customers c ON c.id = o.customer_id
    WHERE c.country = 'DE'
    ORDER BY o.customer_id, o.ordered_at DESC;
About PostgreSQL

What’s distinctive about asking questions of PostgreSQL.

PostgreSQL is an open-source relational database, and for many companies it is the database behind the product itself. The tables were designed for the application, not for reporting: data is normalized across many tables, and column names follow the code more closely than the language the business uses.

Two things follow for anyone asking questions of it. A simple-sounding question often needs several joins. And a phrase such as “active customer” or “net revenue” rarely maps to a single column. In InsightLab you can define internal terms and add reviewed question-and-SQL examples, so your team’s definitions are used when queries are built.

PostgreSQL also organizes tables into schemas inside each database. InsightLab connections can be scoped to specific databases and schemas where supported, so a connection can cover the schemas your team reports on instead of everything in the database.

After the first answer

What your team does with the result.

Most answers lead to another question, and some are worth keeping.

Follow up in the same conversation

Start with monthly revenue, then ask about one channel or one customer. Each result comes back as a table or chart you can keep exploring.

Save charts to a dashboard

Charts from a conversation can be saved to a dashboard. Refresh the underlying queries when you need updated numbers.

Control what queries return

Admins assign workspace roles and configure row- and column-level rules, so a query only returns the records and fields a person is allowed to see.

FAQ

Questions about InsightLab and PostgreSQL.

Do I need to know SQL to query PostgreSQL with InsightLab?

No. You ask a business question in plain language and InsightLab builds the database query, then returns the result as a table or chart. You can ask follow-up questions in the same conversation.

Can InsightLab use our own definitions for metrics stored in PostgreSQL?

Yes. You can define internal terms and add reviewed question-and-SQL examples. InsightLab uses your team’s definitions when it builds queries.

Can we limit which PostgreSQL schemas and rows people can query?

Connections can be scoped to specific databases and schemas where supported. Admins can also configure row-level rules that limit which records a query returns, and column-level rules that restrict sensitive fields.

Is the SQL on this page what InsightLab generates?

No. The queries on this page are hand-written illustrations on a sample schema. They show what business questions look like in PostgreSQL’s dialect. A demo is the place to see how InsightLab handles your team’s questions.

See it answer your team’s questions.

Tell us what your team wants to answer and which sources you use. We’ll walk through the product with you.

Request a demo