Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ It is possible to use more complex expressions in `SELECT`. This is explained in

It is also possible to use a subquery. See [Subquery in `SELECT`](/refguide/oql-clauses/#subquery-in-select) for more details.

### Selecting Attributes over Associations
### Selecting Attributes over Associations {#longpath}

A unique feature of OQL is the ability to access attributes of associated objects using paths. For example:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ This does not apply to the `=` and `!=` operators. Handling of `NULL` in [other

In some databases, using `STRING` type variables in place of numeric, `DATETIME` or `BOOLEAN` values in operators and functions that explicitly require those types, causes the database to perform an implicit conversion. A common example would be the use of a `STRING` representation of a `DATETIME` variable inside a `DATEPART` function. Mendix recommends that you always [cast](#cast) strings to the exact type the operator or functions.

## Functions
## Functions {#functions}

These are the currently supported functions:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ aliases:

## Introduction


OQL statements are translated to SQL statements that are sent to the database.
This can be much faster than retrieving the objects in a microflow and then updating or deleting the resulting list.

Expand Down Expand Up @@ -66,15 +65,15 @@ The syntax of `UPDATE` statements is:

```sql
UPDATE <entity>
SET { <attribute> = <expression> } [ ,...n ]
SET { { <attribute> | <association> } = <expression> } [ ,...n ]
WHERE <condition>
```

`entity` is the entity whose objects are being updated.

`attribute` is an attribute of the entity that is being updated. Multiple attributes can be updated in the same statement.
`attribute` is an attribute of the entity that is being updated. `association` is an association that is being updated. Multiple attributes and associations can be updated in the same statement.

`expression` is a new value of an attribute. Any [OQL expression](/refguide/oql-expressions/) is allowed. The value type of the expression should match the attribute type according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion).
`expression` is a new value of an attribute or association. Any [OQL expression](/refguide/oql-expressions/) is allowed. When updating attributes, the value type of the expression should match the attribute type according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion). In the case of associations, association and entity expressions must match the target association type. Values of type LONG can also be used as association values, but they must be valid ids of associations which are of the target association type.

`condition` can be anything that can appear in an OQL [WHERE clause](/refguide/oql-clauses/#where).

Expand All @@ -89,10 +88,18 @@ SET
FROM Module.Order
WHERE Module.Order_Customer/Module.Customer/ID = Module.Customer/ID
),
Location = Module.Customer_Address/Module.Address/City,
Name = UPPER(Name)
Location = Module.Customer_Address/Module.Address/AddressString,
Name = UPPER(Name),
Module.Customer_Branch = Module.Customer_Address/Module.Address/Module.Address_City/Module.City/Module.Branch_City
```

In the example above, attributes of entity `Module.Customer` are updated using different capabilities of `OQL UPDATE` functionality:

* `TotalAmount` attribute is set to a [subqery](/refguide/oql-clauses/#subquery-in-select) with aggregate function
* `Location` is set to a [path](/refguide/oql-clauses/#longpath) over association to attribute
* `Name` is set using a [function](/refguide/oql-expression-syntax/#functions)
* Association `Module.Customer_Branch` is set to a [path](/refguide/oql-clauses/#longpath) over association to an entity

{{% alert color="info" %}}
Updating attributes was introduced in Mendix 11.3.

Expand Down