Skip to content
Open
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 @@ -23,6 +23,8 @@ From Mendix version 11.3, you can also update object attributes in bulk using OQ

From Mendix version 11.4, you can update object associations as well as attributes in bulk using OQL `UPDATE` statements.

From Mendix version 11.6, you can insert new objects with attributes in bulk using OQL `INSERT` statements.

{{% /alert %}}

## Java API for OQL updates
Expand Down Expand Up @@ -160,6 +162,36 @@ WHERE ID IN (
WHERE Module.Customer/Name = 'Mary' )
```

## `INSERT` Statement {#oql-insert}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this above UPDATE. Although we implemented it last, intuitively it is the first statement type to learn and use. Also, that would resolve the fact that ## Joins section is in the middle of statement types

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, it is the one I have heard the least use cases for, so I wouldn't think it's the first to use. As to the Joins section, it only applies to deletes and updates, which is emphasized by the current order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, so let's keep it like this then.


The syntax of `INSERT` statements is:

```sql
INSERT INTO <entity> ( <attribute> [ ,...n ] ) <oql-query>
```

`entity` is the entity for which new objects will be created.

`attribute` is an attribute of the entity that will be inserted.

`oql-query` is any OQL query that returns same number of columns as the number of attributes that will be inserted.
This query can select data from persistable entities and/or [view entities](/refguide/view-entities/).

Example:

```sql
INSERT INTO Module.Order ( OrderNumber, CustomerNumber )
SELECT NewOrderNumber, Loader.TemporaryData_Customer/Loader.Customer/Number FROM Loader.TemporaryData
```

### OQL `INSERT` Limitations

* It is not yet possible to insert associations. As a workaround, they can be added after the `INSERT` using an OQL `UPDATE` statement.
* Attributes of type "Date and time" with a default value of `'[%CurrentDateTime%]'` will not have their default values set when the `INSERT` statement does not specify them.
As a workaround, explicitly insert the attribute with a value of `'[%CurrentDatetime%]'` in the `SELECT` part.
* When using Oracle, due to database limitations, inserting attributes of type unlimited string or binary is not supported.
* The general limitations for OQL statements also apply. See [General Limitations for OQL Statements](#oql-limitations), below.

## General Limitations for OQL Statements {#oql-limitations}

* OQL statements can be used only with persistable entities.
Expand Down