Skip to main content

Data Querying

Lido provides QUERYTABLE, which lets you run SQL queries directly against your Lido tables. This is a non-action formula — it executes immediately and returns the query result as a cell range.


QUERYTABLE

Runs a SQL query against one or more Lido tables and returns the result as a 2D range. Under the hood, Lido loads your table data into an in-memory PostgreSQL database (PGlite) and executes the query.

Syntax:

=QUERYTABLE(query)
=QUERYTABLE(query, return_headers)

Parameters:

ParameterDescriptionRequired
queryA SQL query string referencing Lido table namesYes
return_headersIf FALSE, omits column headers from the result (default: TRUE)No

Examples:

=QUERYTABLE("SELECT * FROM Orders WHERE Status = 'Pending'")

Returns all rows from the Orders table where Status is "Pending", with column headers in the first row.

=QUERYTABLE("SELECT Region, SUM(Revenue) as Total FROM Clients GROUP BY Region ORDER BY Total DESC")

Aggregates revenue by region from the Clients table.

=QUERYTABLE("SELECT o.OrderID, c.Name FROM Orders o JOIN Clients c ON o.ClientID = c.ID")

Joins two Lido tables together.

How It Works

  1. QUERYTABLE parses your SQL to identify which table names are referenced
  2. For each table, it loads the current table data (including column types) into an in-memory PostgreSQL instance
  3. The query is executed and results are returned as a cell range
  4. Column types are preserved — numeric columns remain numbers, booleans remain booleans, etc.

Supported SQL

QUERYTABLE supports standard PostgreSQL SQL syntax, including:

  • SELECT, WHERE, ORDER BY, GROUP BY, HAVING, LIMIT
  • Aggregate functions: SUM, COUNT, AVG, MIN, MAX
  • JOIN across multiple Lido tables
  • Subqueries
  • String functions, date functions, and more

Tips

  • Table names in the query must match your Lido table names exactly (case-sensitive)
  • The result updates automatically when the source table data changes
  • Use return_headers = FALSE when feeding the result into another formula that doesn't expect headers
  • For very large tables, be mindful that the entire table is loaded into memory for query execution