DATABASE Run database query function

Execute a SQL SELECT query against a database and store the results.

Help CentreBuilding Processes

This article describes the RPA Database functionality to execute a SELECT query.

For a full list of available functions, please read DATABASE functions.


Description

The Run database query function executes a SELECT query against a database and returns the results as an array of dictionaries. Each dictionary represents a row, with column names as keys. You can use a named connection or provide inline connection details for legacy compatibility.


Setting it up

To use the Run database query function, follow these instructions:

{{popups:rpas/add:action=db-query}}

Once on a process map:

  1. Navigate to the process where you would like to add the Run database query function
  2. Click on the green button's drop-down (right side of the green button labelled "Process")
  3. On the menu that appears, click on the "+ Activity" item
  4. From here you can select the Run database query option
  5. Click "Add" once you are done

Input parameters

ParameterRequiredTypeDefaultDescription
NameNoText-The alias of a previously opened connection (from db-connect)
QueryYesText-The SQL SELECT statement to execute
ParamsNoArray-An array of values for parameterised queries (use %s or ? as placeholders)
TypeNoSelect-Database type (legacy mode – use db-connect instead)
HostNoText-Database host (legacy mode)
PortNoNumber-Database port (legacy mode)
DatabaseNoText-Database name (legacy mode)
UsernameNoText-Database username (legacy mode)
VariableNoTextqueryVariable name to store the query results

Output variables

VariableTypeDescription
{query}Array of dictionariesThe query results, where each dictionary represents a row with column names as keys

Errors

ErrorDescription
Connection failedUnable to connect to the database (when using legacy inline connection)
Query errorThe SQL query contains a syntax error or references invalid objects
Authentication failedThe username or password is incorrect (when using legacy inline connection)

Tips

  • Use parameterised queries with %s or ? placeholders to prevent SQL injection
  • Use named connections (db-connect) for efficiency – legacy inline mode creates a new connection each time
  • Add LIMIT to large result sets to avoid memory issues
  • The results can be iterated with the "Each record in a list" loop action

Related functions

See it working on your own data

Everything documented here ships with the platform – try the document tools free, or go live in 7 days.