Create a view
Describe the data your reports can use: an SQL query and a list of fields.
On this page
A view tells OpenReports which data reports may use. It is a short JSON document with an SQL query and one entry for each column that people can pick. You write it in the Views screen.

Create the view
- Select Views (the layers icon) in the bar on the left.
- Select Create. The View specification editor opens with an example.
- Replace the example with your view, then select SUBMIT.
The view appears as a card in the Views screen. It is ready to use in reports.
An example
This view reads a table of orders:
{
"id": "orders",
"name": "Orders",
"sql": "SELECT customer, country, product, quantity, total, paid, dtcreated FROM demo_orders",
"fields": [
{ "column": "customer", "name": "Customer", "type": "string", "group": true },
{ "column": "country", "name": "Country", "type": "string", "group": true },
{ "column": "product", "name": "Product", "type": "string", "group": true },
{ "column": "quantity", "name": "Quantity", "type": "number" },
{ "output": "@", "column": "total", "name": "Total", "type": "number", "format": 2 },
{ "column": "paid", "name": "Paid", "type": "boolean" },
{ "column": "dtcreated", "name": "Created", "type": "date", "group": true }
]
}
sqlselects the data. It can join tables, compute columns and useWHERE, like anySELECT.- Each entry in
fieldsnames a column of that query, the name people see (name) and its type (type):string,number,booleanordate. "group": truelets reports group rows by this field.
Every key is described in View definition.
Tips
- Run the SQL in
psqlor another client first. If the SQL is wrong, the report shows no useful data. - The
idof each view must be unique. Saving a view with theidof another view replaces that view. - People see only the fields you list, even if the query returns more columns.
Next: Create a report.