Skip to content

Commit b6b0d02

Browse files
committed
Add documentation on OQL INSERT statement
1 parent f88bb1e commit b6b0d02

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

content/en/docs/refguide/modeling/domain-model/oql/oql-statements.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ From Mendix version 11.3, you can also update object attributes in bulk using OQ
2323

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

26+
From Mendix version 11.6, you can insert new objects with attributes in bulk using OQL `INSERT` statements.
27+
2628
{{% /alert %}}
2729

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

165+
## `INSERT` Statement {#oql-insert}
166+
167+
The syntax of `INSERT` statements is:
168+
169+
```sql
170+
INSERT INTO <entity> ( <attribute> [ ,...n ] ) <oql-query>
171+
```
172+
173+
`entity` is the entity for which new objects will be created.
174+
175+
`attribute` is an attribute of the entity that will be inserted.
176+
177+
`oql-query` is any OQL query that returns same number of columns as the number of attributes that will be inserted.
178+
This query can select data from persistable entities and/or [view entities](/refguide/view-entities/).
179+
180+
Example:
181+
182+
```sql
183+
INSERT INTO Module.Order ( OrderNumber, CustomerNumber )
184+
SELECT NewOrderNumber, Loader.TemporaryData_Customer/Loader.Customer/Number FROM Loader.TemporaryData
185+
```
186+
187+
### OQL `INSERT` Limitations
188+
189+
* It is not yet possible to insert associations. As a workaround, they can be added after the `INSERT` using an OQL `UPDATE` statement.
190+
* 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.
191+
As a workaround, explicitly insert the attribute with a value of `'[%CurrentDatetime%]'` in the `SELECT` part.
192+
* When using Oracle, due to database limitations, inserting attributes of type unlimited string or binary is not supported.
193+
* The general limitations for OQL statements also apply. See [General Limitations for OQL Statements](#oql-limitations), below.
194+
163195
## General Limitations for OQL Statements {#oql-limitations}
164196

165197
* OQL statements can be used only with persistable entities.

0 commit comments

Comments
 (0)