Script Example
In this article
Suppose you need to load new data from a database into the system and generate a report based on the retrieved information. To accomplish this, you can create a script consisting of four blocks:
- Scheduler to run the script at specific time
- SQL Query to delete the existing data
- SQL Query to retrieve new data
- Insert rows to insert new data into a table in the Data Model
- In the first block, Scheduler, set the schedule for the script execution.
- In the second block, specify from where the data should be deleted, for example, from the table into which you are going to insert the retrieved data. Enter the SQL query. Deleting data is necessary to avoid duplication each time the script runs.
When accessing a different database, you can use the following SQL query:
truncate table if exists `db_name`.`table_name` - In the third block, use an SQL query to select new data and specify the source. You can enter the table name manually or click the Table field to select it from the list.
When working with a PostgreSQL connection, you can use this SQL query:
select * from public.table_name - In the fourth block, select the table into which you want to insert new data or create a new one. Use mapping to specify from which database column the value should be taken. You can select the appropriate mapping fields either by clicking on the target table column or using the mapping field tree in the panel that opens. When you hover over a column, a tooltip with the data type appears.
Important
The block configuration is considered complete after it has been tested. Therefore, mapping values from the previous block become available only after the block has been tested.
Once executed, the script loads the required information from the selected database into the system.
Was the article helpful?
Yes
No