Find the records you need.
Filter by the fields that matter, sort the result and return the right records for an application screen.
SQL
Build application screens, combine related facts and turn activity into useful summaries. Query structured data in the same engine as your vectors, relationships and searchable text.
| id | title | status |
|---|---|---|
| 01 | Getting started | published |
| 02 | Release notes | draft |
| 03 | API guide | published |
WHERE status = $1published Choose the fields. Apply a condition.
Use the result in your application.
Everyday application queries
Start with the record behind a screen. Add relationships and summaries as the question grows.
Filter by the fields that matter, sort the result and return the right records for an application screen.
Connect records across tables to answer questions that need more than one part of your data.
Group records and calculate totals for reports, operational views and the decisions behind them.
SQL features depend on your configuration and supported query surface. Explore the SQL reference.
A query for the task
Use familiar SQL patterns to read and shape your records. Bind values as parameters and keep the result easy for your application to use.
Read supported SQL syntax
These examples assume tables named app.records and app.groups.
No query runs on this page.
Return a bounded set of records with a matching status.
SELECT id, title
FROM app.records
WHERE status = $1
ORDER BY id
LIMIT 20;
Pass the status in the parameters array, rather than joining user input into the SQL string.
Add a group's label to the records that belong to it.
SELECT r.id, r.title, g.label
FROM app.records AS r
JOIN app.groups AS g
ON r.group_id = g.id;
Use explicit aliases so your application can distinguish columns returned from different tables.
Count the records in each status.
SELECT status, COUNT(*) AS total
FROM app.records
GROUP BY status;
Filter input rows with WHERE; use HAVING when the condition applies to an aggregated group.
Understand the work
See how a query reaches its answer before deciding what to tune.
Use EXPLAIN to inspect scans, indexes, joins and aggregation stages.
Filter the input, return the columns you need and review where an index can help.
EXPLAIN ANALYZE executes the query and reports measurements so you can compare
its work.
Build in your workflow
Work through an API, an SDK or a supported PostgreSQL connection.
Use the current read-only login from an enabled dedicated PostgreSQL listener.
Connect a SQL clientCheck the SQL your ORM generates. Use HTTPS for writes and schema changes; the current PostgreSQL login is read-only.
Review compatibilitySend parameterized SQL from your application and work with the returned rows.
Choose an SDKPostgreSQL protocol support has a documented scope. Check your application's SQL and ORM operations against the deployed instance.
See the whole databaseBuild with OriginChainDB