AmazonRedshiftQuery

Use this activity to execute a simple or a complex SQL Query on an Amazon Redshift database. The AmazonRedshiftQuery activity returns information in the form of rows.

Configuration

The Configuration tab has the following fields:

Field Description
Connection Name of the Amazon Redshift database connection from which to retrieve information. You can select a connection from the drop-down list.

Input Settings

The Input Settings tab has the following fields:

Field Description
Query An SQL statement used to query the database. The query can be a simple query or a complex query. A complex query has nested SQL statements. You can construct prepared SQL queries by using substitution variables (or parameters) of the form ?<fieldname> in the query statement. For example, select firstname, lastname, age from users where firstname='?firstname' and age < '?age';
Each substitution variable identifies an input parameter whose mapped value will be substituted into the substitution variable at runtime. You can reuse the substitution variable for the same input parameter elsewhere in the query. Input parameters used in the WHERE clause, and output parameters used in the SELECT clause, and their corresponding type information is automatically fetched from the database using the selected connection for the entered query. Input and output fields in the Input and Output tabs of the activity are also automatically generated.
Note: Be sure to include the semicolon (;) at the end of the query. This activity expects a query to end with a semicolon to indicate the end of the query. A missing semicolon at the end of the query results in the query hanging.
The following examples represent simple and complex queries:
  • Simple query example:

    SELECT * FROM users;

    For the above query, the output fields are generated from the table user's column information.

    SELECT username, firstname, lastname 
        FROM users 
        WHERE state = '?state' and likesports = '?likesports' and liketheatre = '?liketheatre' and likejazz = 'true';

    For the above query, output fields are generated for username, firstname and lastname and input fields are generated for state (string), likesports (boolean), liketheatre (bool) and likejazz (bool). Also the mapped values for the fields, state, likesports and liketheatre are substituted into the substitution variables ?state, ?likesports and ?liketheatre at runtime.

  • Nested query example:

    SELECT firstname, lastname, total_quantity
        FROM (SELECT buyerid, sum(qtysold) total_quantity
                FROM sales
                GROUP BY buyerid
                ORDER BY total_quantity desc limit 10) Q, users
        WHERE Q.buyerid = userid
        ORDER BY Q.total_quantity desc;
    
Fields The grid is provided for informational purpose only.

Input

This tab contains the input schema. The fields that were selected in the Input Settings tab will be available in the schema. You can either hard code their values or map them to a field from the output of a preceding activity in the flow using the Mapper.

Output

This tab displays the activity output schema in a tree structure format. The output of an activity is displayed for informational purposes only and cannot be modified or altered. The information in this schema varies depending on the fields that you selected in the Input Settings tab.

The properties that are displayed in the Output tab schema correspond to the output of this activity and can be used as input by subsequent activities in the flow.