| ... | ... | @@ -172,31 +172,78 @@ Use `+columns` to get all columns of the base table plus certain ones from joine |
|
|
|
|
|
|
|
# Select and As
|
|
|
|
|
|
|
|
RESTRICTIONS: keys and values may not contain spaces.
|
|
|
|
The "select" and "as" attribues allow even more flexibility to define exactly what should be returned than "columns" does. Other than renaming a column,
|
|
|
|
functions may be used to select calculated values.
|
|
|
|
|
|
|
|
The "select" and "as" attribues allow even more flexibility to define exactly what should be returned than "columns" does.
|
|
|
|
## Restrictions
|
|
|
|
|
|
|
|
```JSON
|
|
|
|
"attrs" : {
|
|
|
|
"join": [ "contracts__working_time_constraint" ],
|
|
|
|
"select": [ {"min" : "max_hours_per_day"} ],
|
|
|
|
"as": [ "min_max" ]
|
|
|
|
Keys and values may not contain spaces.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
Only select one column and name it "me_id" from system.entity:
|
|
|
|
|
|
|
|
`POST /data/system/entity/query`
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"attrs": {
|
|
|
|
"select": "me.id",
|
|
|
|
"as": "me_id"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Result:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"data": [
|
|
|
|
{
|
|
|
|
"me_id": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"me_id": 2
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Select the maximum id from system.entity:
|
|
|
|
|
|
|
|
`POST /data/system/entity/query`
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"attrs": {
|
|
|
|
"select": [
|
|
|
|
{
|
|
|
|
"max": "me.id"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"as": [
|
|
|
|
"max_id"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Generates:
|
|
|
|
|
|
|
|
```SQL
|
|
|
|
SELECT MIN( max_hours_per_day )
|
|
|
|
FROM contracts.collective_agreement() me
|
|
|
|
LEFT JOIN contracts.working_time_constraint() contracts_working_time_constraint ON contracts_working_time_constraint.collective_agreement = me.id
|
|
|
|
LIMIT 10
|
|
|
|
```sql
|
|
|
|
SELECT MAX( me.id ) FROM system.entity()
|
|
|
|
```
|
|
|
|
|
|
|
|
Returns one row:
|
|
|
|
```JSON
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"min_max": "9"
|
|
|
|
"data": [
|
|
|
|
{
|
|
|
|
"max_id": 99
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
| ... | ... | |