Create List from SQL
Audience:
Low-code EngineersSkill Prerequisites:
Actions,Lists,SQL,Tokens
Runs a SQL query and saves every row it returns as a list. Each row becomes one list item, and each column becomes a property of that item.
You can then go through the list with Execute Actions for each List Entry, or use it with the other list actions. The number of items is saved in the [<List Name>:Count] token.
The list only exists while the actions run. It isn't saved anywhere and isn't a Plant an App entity.
This action requires the Data Integration feature (Standard) to be licensed. If it isn't, the action fails with a message that the feature is unlicensed.
Typical Use Cases
- Send an email to every contact returned by a query
- Export query results to a file with Create CSV from List or Create Excel from List
- Return rows as JSON with List to JSON
- Copy rows from one database to another, with a different connection and Import List into Database
- Run the same actions for each row, for example to call an API for each pending record
Don't use it to
- Read a single row into tokens, or run an
INSERT,UPDATEorDELETE. Use Run SQL Query instead. - Load users to act on them, such as granting roles. Use Load Users from SQL instead.
- Export a large result to Excel. Use Create Excel from SQL query, which doesn't need a list.
Related Actions
| Action Name | Description |
|---|---|
| Execute Actions for each List Entry | Runs actions once for each item in the list. |
| Run SQL Query | Runs SQL and saves the first row in tokens. |
| Create List from JSON | Creates a list from a JSON array. |
| Create CSV from List | Writes the list to a CSV file or token. |
| Create Excel from List | Writes the list to an Excel (.xlsx) file. |
| List to JSON | Turns the list into a JSON array. |
| Import List into Database | Saves the items of a list into a database table. |
| Paginate List | Keeps one page of the list. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Database | A Database connector to run the query against. If it's empty, the application database is used. See Connection. | No | empty | No |
| Override Connection String | A connection string, or the name of a connection string from web.config. When it's filled in, it's used instead of Database. See Connection. | Yes | empty string | No |
| Query Timeout | How many seconds the query can run before it times out. Empty or 0 means 600 seconds (10 minutes). Values from 1 to 9 are raised to 10. Negative or non-numeric values make the action fail. | Yes | 600 | No |
| SQL Query | The query that returns the rows. Tokens are replaced with SQL-safe text, but you add the quotes. See Tokens in the query. | Yes | empty string | Yes |
| Bind Tokens | Parameters for the query. Each row has a Parameter Name, for example CustomerId, and a Parameter Value, for example [CustomerId]. Use @CustomerId in the query. This is the safest way to pass values. | Yes (values) | empty | No |
| List Name | The name of the list, for example OrdersList. If a list with this name already exists, the rows are added to it, unless Clear before loading is on. | Yes | empty string | Yes |
| Clear before loading | Starts with an empty list, so the rows replace the items of an existing list with the same name. | No | false | No |
| Properties | Chooses which columns to keep and what to call them. Each row has a SQL Column, for example EmailAddress, and a List Property, for example Email. With no rows, every column is kept with its own name. See Columns and properties. | Yes (SQL Column) | empty | No |
| On Error | Actions to run if the query fails. They can use the [Exception], [ExceptionType], [ExceptionMessage] and [ExceptionStack] tokens. See Errors. | No | empty | No |
Output Parameters Reference
| Output | Description |
|---|---|
List <List Name> | The list, with one item for each row. |
[<List Name>:Count] | The number of items in the list, for example [OrdersList:Count]. When rows were added to an existing list, it's the total, not just the new rows. |
Columns and properties
- With no Properties, each item gets one property per column, named like the column. Give computed columns a name, for example
SELECT COUNT(*) AS OrderCount. - With Properties, only the listed columns are kept. Square brackets around a List Property are removed, so
[Email]becomesEmail. Every SQL Column must be in the result, or the action fails. - Values keep their database types. Numbers stay numbers and dates stay dates. This matters for actions that write the values, such as List to JSON or Import List into Database.
NULLbecomes an empty value.
Inside Execute Actions for each List Entry, use the properties as [ListName:PropertyName], for example [OrdersList:Email].