Saturday, October 21, 2023

Emojis - SQL in ICM InfoWorks - 📥4 Insertion 📥

 4 Insertion 📥

It is possible to insert objects into the network and insert rows into blobs. 🗃️

To add individual objects the syntax is: 📝

INSERT INTO📋<table name> (field1, field 2,... fieldn) VALUES (val1,val2,... valn) 🖊️

INSERT INTO node (node_id,x,y) VALUES ('N1', 123, 456) 📍

The number of values must match the number of fields. All the values can be scalar expressions e.g. scalar variables, expressing including scalar variables. 📈

To add individual rows into an individual object's structured blob the syntax is: 📜

INSERT INTO 📋<table name>.<blob name> (field1,field,2... fieldn) VALUES (val1,val2,... valn) 📌

The field names must be either: 🔍

  • a key field name of the table 🔑
  • the array name followed by a . followed by a field in the blob 📊

All key field names of the table must be specified and objects into which lines in the structure blob are being inserted must exist. 📁

To insert values into a table from a SELECT statement, the syntax is: 📖

INSERT INTO 📋<table name> (field1,field2,... fieldn) SELECT <select statement> 📚

To insert values into a structure blob from a SELECT statement the syntax is: 📘

INSERT INTO 📋<table name>.<blob name>(field1,field2,... fieldn) SELECT <select statement> 📙

As with the values insert statement, the field names must be either:

  • a key field name of the table 🔑
  • the array name followed by a . followed by a field in the blob 📊

All key field names of the table must be specified and the objects into which lines are being inserted must exist. 📁

The number of items being selected must match the number of fields being set in the INSERT. ✅

The select statement can include WHERE and ORDER BY but not GROUP BY or HAVING and can include selection of SCENARIO, TOP and BOTTOM and SELECTED etc. 🔄

It is possible to add objects to a scenario by adding the scenario details after the list of fields e.g. 🎬

INSERT INTO node(node_id,x,y) IN BASE SCENARIO VALUES ('N2',3,4) 🎥

INSERT INTO node(node_id,x,y) IN SCENARIO 'SC1' VALUES ('N3,4,5) 📽️

5 Assignment 🖋️ As well as selecting, deselecting and deleting objects, it is possible to use SQL to set values for fields in objects in the InfoWorks ICM networks. If you wish to set values for fields for objects in the default table, this may be done with the SET keyword. 🛠️

It is possible but not necessary to have a WHERE sub-clause. As with selection, deselection and deletion, values will either be set for all objects or only for selected objects depending on the setting of the check-box. ✅❌

If you do not have a WHERE sub-clause then the assignment will be done for all objects or all selected objects, otherwise it will only be performed for the objects for which the WHERE sub-clause is true. 🌟

It is possible to perform more than one assignment at once by separating them with commas. 🖍️

Examples:

SET user_number_1 = 123 💼 SET user_number_2 = user_number_1 / width 📏

SET user_number_1 = 123 WHERE x > 10000 AND y > 12000 🗺️

SET user_number_1 = x, user_number_2 = y 🧮

SET user_text_1 = 'XXX'+node_id, user_text_2 = asset_id WHERE width > 200 🎨 When you have more than one assignment in a clause separated by commas they are performed from left to right, so it is safe to assume that the value of a field in one assignment will be the value that it would be after performing the previous assignments in that clause. ➡️

It is possible to override the default table and the default selection behaviour. In both cases this is achieved by using the UPDATE keyword. 🔄

To override the default table, the clause should begin with UPDATE followed by the table name followed by the keyword SET and the rest of the clause as above e.g. 🔄📋

UPDATE [All Links] SET asset_id = '' 📌

UPDATE [All Links] SET asset_id = '', user_number_1 = 0.0 WHERE width > 200 📐

To override the default selection behaviour, begin the clause with UPDATE ALL or UPDATE SELECTED as appropriate. 🌐

To override both these two mechanisms should be combined e.g. 🔄➕

UPDATE SELECTED Node SET user_number_1 = 123.45 🖍️

It is possible to set fields to the NULL value described above e.g. ❓

SET ground_level = NULL ❌

No comments:

AI Rivers of Wisdom about ICM SWMM

Here's the text "Rivers of Wisdom" formatted with one sentence per line: [Verse 1] 🌊 Beneath the ancient oak, where shadows p...