post https://api.sort.xyz/v2/orgs//queries
Create a saved query you can share with your team or just execute again later.
The query
field can either be a SQL query or an Intent query. An Intent query is a flexible format which can also be used from the Sort UI to create Change Requests. SQL queries are plain SQL which provides maximum flexibility but no support for Change Requests in the Sort UI.
Let's look at some examples:
SQL Query
Request body
{
"name": "Products SQL query",
"description": "This query is amazing because it uses SQL to select from a table.",
"database_slug": "database-fake39x",
"query": {
"type": "sql",
"sql": "SELECT id, name, price FROM public.products WHERE price > 10.23 ORDER BY price DESC LIMIT 10"
}
}
Intent Query request body
{
"name": "Products Intent query",
"description": "This uses an Intent query format because I want my team to easily change this data later.",
"database_slug": "database-fake39x",
"query": {
"type": "intent",
"intent": {
"dml": "SELECT",
"schema": "public",
"table": "products",
"columns": [
"id", "name", "price"
],
"filters": [
{
"column": "price",
"op": ">",
"value": "10.23"
}
],
"combinator": "AND",
"orders": [
{
"column": "price",
"direction": "DESC"
}
],
"limit": 10
}
}
}