Script activity in Data Factory and Azure Synapse Analytics

In this article, you learn how to create a script activity in Azure Data Factory to run custom PostgreSQL queries. By using script activity, you can execute various types of PostgreSQL commands, such as Data Manipulation Language (DML) and Data Definition Language (DDL) commands, directly in your pipelines.

DML statements: INSERT, UPDATE, DELETE, and SELECT

DDL statements: CREATE, ALTER, and DROP

Prerequisites

Create a script activity

  1. In Azure Data Factory Studio, select the Author hub. Hover over the Pipelines section, select ... at the left, and select New pipeline to create a new pipeline.

    Screenshot showing where to select author in Azure Data Factory.

    Screenshot showing where to select new pipeline.

  2. Under General, drag and drop the script activity into the pipeline.

    Screenshot showing where to select script activity.

  3. At the General tab, give your script activity a name.

    Screenshot showing texbox to provide a name to the script activity.

  4. Switch to the Settings tab and select your Azure Database for PostgreSQL linked service, or create a new one. Once added, select Test connection to verify your connection is valid.

    Screenshot showing an example setting linked service.

  5. Select either the Query or NonQuery option depending on your script.

    The script activity supports both query and nonquery statements.

    Screenshot showing Query and NonQuery radio buttons.

Query statements execute PostgreSQL statements that return results, often SELECT statements. A query statement returns records of data.

Screenshot that shows a sample of query script.

Sample of a payload with a query.

{
      "name": "Sample of select statement",
      "type": "Script",
      "dependsOn": [],
      "policy": {
         "timeout": "1.12:00:00",
         "retry": 0,
         "retryIntervalInSeconds": 30,
         "secureOutput": false,
         "secureInput": false
      },
      "userProperties": [],
      "linkedServiceName": {
         "referenceName": "AzurePostgreSQL",
         "type": "LinkedServiceReference"
      },
      "typeProperties": {
         "scripts": [
            {
                  "type": "Query",
                  "text": "SELECT * FROM sample_table WHERE sample_int = 100; "
            }
         ],
         "scriptBlockExecutionTimeout": "02:00:00"
      }
}