Athena / Client / get_query_results

get_query_results#

Athena.Client.get_query_results(**kwargs)#

Streams the results of a single query execution specified by QueryExecutionId from the Athena query results location in Amazon S3. For more information, see Working with query results, recent queries, and output files in the Amazon Athena User Guide. This request does not execute the query but returns results. Use StartQueryExecution to run a query.

To stream query results successfully, the IAM principal with permission to call GetQueryResults also must have permissions to the Amazon S3 GetObject action for the Athena query results location.

Warning

IAM principals with permission to the Amazon S3 GetObject action for the query results location are able to retrieve query results from Amazon S3 even if permission to the GetQueryResults action is denied. To restrict user or role access, ensure that Amazon S3 permissions to the Athena query location are denied.

See also: AWS API Documentation

Request Syntax

response = client.get_query_results(
    QueryExecutionId='string',
    NextToken='string',
    MaxResults=123
)
Parameters:
  • QueryExecutionId (string) –

    [REQUIRED]

    The unique ID of the query execution.

  • NextToken (string) – A token generated by the Athena service that specifies where to continue pagination if a previous request was truncated. To obtain the next set of pages, pass in the NextToken from the response object of the previous page call.

  • MaxResults (integer) – The maximum number of results (rows) to return in this request.

Return type:

dict

Returns:

Response Syntax

{
    'UpdateCount': 123,
    'ResultSet': {
        'Rows': [
            {
                'Data': [
                    {
                        'VarCharValue': 'string'
                    },
                ]
            },
        ],
        'ResultSetMetadata': {
            'ColumnInfo': [
                {
                    'CatalogName': 'string',
                    'SchemaName': 'string',
                    'TableName': 'string',
                    'Name': 'string',
                    'Label': 'string',
                    'Type': 'string',
                    'Precision': 123,
                    'Scale': 123,
                    'Nullable': 'NOT_NULL'|'NULLABLE'|'UNKNOWN',
                    'CaseSensitive': True|False
                },
            ]
        }
    },
    'NextToken': 'string'
}

Response Structure

  • (dict) –

    • UpdateCount (integer) –

      The number of rows inserted with a CREATE TABLE AS SELECT, INSERT INTO, or UPDATE statement.

    • ResultSet (dict) –

      The results of the query execution.

      • Rows (list) –

        The rows in the table.

        • (dict) –

          The rows that make up a query result table.

          • Data (list) –

            The data that populates a row in a query result table.

            • (dict) –

              A piece of data (a field in the table).

              • VarCharValue (string) –

                The value of the datum.

      • ResultSetMetadata (dict) –

        The metadata that describes the column structure and data types of a table of query results.

        • ColumnInfo (list) –

          Information about the columns returned in a query result metadata.

          • (dict) –

            Information about the columns in a query execution result.

            • CatalogName (string) –

              The catalog to which the query results belong.

            • SchemaName (string) –

              The schema name (database name) to which the query results belong.

            • TableName (string) –

              The table name for the query results.

            • Name (string) –

              The name of the column.

            • Label (string) –

              A column label.

            • Type (string) –

              The data type of the column.

            • Precision (integer) –

              For DECIMAL data types, specifies the total number of digits, up to 38. For performance reasons, we recommend up to 18 digits.

            • Scale (integer) –

              For DECIMAL data types, specifies the total number of digits in the fractional part of the value. Defaults to 0.

            • Nullable (string) –

              Unsupported constraint. This value always shows as UNKNOWN.

            • CaseSensitive (boolean) –

              Indicates whether values in the column are case-sensitive.

    • NextToken (string) –

      A token generated by the Athena service that specifies where to continue pagination if a previous request was truncated. To obtain the next set of pages, pass in the NextToken from the response object of the previous page call.

Exceptions