Skip to content

Commit 2c4ae2d

Browse files
authored
Merge pull request #11543 from passalaqua/dat/feature/insert-values
Document new OQL feature: INSERT ... `VALUES`
2 parents cf612fb + ced3bb1 commit 2c4ae2d

1 file changed

Lines changed: 40 additions & 3 deletions

File tree

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,23 @@ SET
156156

157157
## `INSERT` Statement {#oql-insert}
158158

159+
You can use the `INSERT` statement to insert new entity objects into your data. You can do this in two ways:
160+
161+
* using an OQL query – extracting data and use it to insert one or more new objects
162+
* using values – specifying explicit values and use these to insert one or more new objects
163+
159164
{{% alert color="info" %}}
160-
Available from Mendix version 11.6.0
165+
Available from Mendix version 11.6.0.
166+
You can use an OQL query from Mendix version 11.6.0.
167+
You can use values from Mendix version 11.13.0.
161168
{{% /alert %}}
162169

163-
The syntax of `INSERT` statements is:
170+
### `INSERT` with OQL Query
171+
172+
Insert with OQL query allows you to extract data using an OQL query and insert those values as one or more entity objects.
164173

165174
```sql
166-
INSERT INTO <entity> ( <attribute | <association> [ , …n ] ) <oql-query>
175+
INSERT INTO <entity> ( <attribute> | <association> [ , …n ] ) <oql-query>
167176
```
168177

169178
* `entity` is the entity for which new objects will be created.
@@ -182,6 +191,34 @@ INSERT INTO Module.Order ( OrderNumber, CustomerNumber, Module.Order_Customer )
182191
SELECT NewOrderNumber, Loader.TemporaryData_Customer/Loader.Customer/Number, Loader.TemporaryData_Customer FROM Loader.TemporaryData
183192
```
184193

194+
### `INSERT` with Values
195+
196+
Insert with values allows you to insert a list of literals, OQL parameters, and OQL expressions as one or more entity objects.
197+
198+
```sql
199+
INSERT INTO <entity> ( <attribute> [ , …n ] ) VALUES (<expression 1> [, …<expression n>]) [ …, (<expression 1> [, …<expression n>])]
200+
```
201+
202+
* `entity` is the entity for which new objects will be created.
203+
204+
* `attribute` is an attribute of the entity that will be inserted.
205+
206+
{{% alert color="info" %}}You cannot insert associations when inserting with values.{{% /alert %}}
207+
208+
* `expression x` is any valid expression consisting solely of literals or OQL expressions. Every row must contain the same number of values of compatible types as the list of attributes you are inserting for each entity object.
209+
210+
{{% alert color="info" %}}This expression cannot use OQL clauses to select data from any entities.{{% /alert %}}
211+
212+
Example:
213+
214+
```sql
215+
INSERT INTO Module.Person ( Name, BirthDate )
216+
VALUES
217+
( 'Person A', DATEPARSE('01 Jan 1970', 'dd MMM yyyy') ),
218+
( 'Person B', DATEPARSE('20 Mar 1990', 'dd MMM yyyy') ),
219+
( 'Person C', DATEPARSE('14 Jul 1988', 'dd MMM yyyy') )
220+
```
221+
185222
### OQL `INSERT` Limitations
186223

187224
* Only a single value can be specified per association.

0 commit comments

Comments
 (0)