AWS Athena truncate table using BOTO3

Viewed 2052

I am trying to truncate Athena table using boto3, it is failing with error :

  File "staging_layer_schema.py", line 142, in <module>
    ResultConfiguration = config
  File "/usr/local/lib/python3.6/dist-packages/botocore/client.py", line 316, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.6/dist-packages/botocore/client.py", line 635, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidRequestException: An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: Queries of this type are not supported

Please find below code snippet as well :

truncate_staging_table_query = "truncate table pratik_test_staging.temp"
response_truncate_staging_table_query = client_athena.start_query_execution(
          QueryString = truncate_staging_table_query, 
          ResultConfiguration = config
)
1 Answers

You cannot truncate a table in Athena, the table is more like a logical representation of the data that will be retrieved from your datasource.

Everytime you perform the query, data is loaded from your datasource and then translated to match the table schema so that it can be interacted like a SQL table.

Heres some more information that should explain in a greater depth: Understanding Tables, Databases, and the Data Catalog - Amazon Athena

Related