Column cannot be resolved, Querying Athena through Lambda and boto3

0

Good afternoon fellow AWS users.

I'm trying to get data from Athena into a Lambda session. I've done this before with another dataset, with no problems, so I know the Python script is correctly querying Athena.

I've recently had to change from one table to another, which is located in a separate database, and now my lambda script is failing.

I'll need to provide some context of how I'm viewing the error in the output logs, so:

import boto3

#get athena clint
client = boto3.client('athena')

#define sql query string
query = f"""
        select "column_1" from table
     """
 
#run query
queryStart = client.start_query_execution(
            QueryString = query,
            QueryExecutionContext = {
                'Database': 'database',
                'Catalog' : 'catalog'
            }
        )

#get current state of execution
queryExecution = client.get_query_execution(QueryExecutionId=queryStart['QueryExecutionId'])

The queryExecution object attribute ["QueryExecution"]["Status"]["State"] is "FAILED", and the attribute ["QueryExecution"]["Status"]["StateChangeReason"] is:

SYNTAX_ERROR: line 1:8: Column 'column_1' cannot be resolved

The query works fine in Athena.

I have permission for all resources, and all actions, on both Lake Formation and Athena.

I've tried putting the column in double quotes, I've tried giving the table an alias, I've tried backticks, checking letter cases, everything.

Also, when I change the query string to

#define sql query string
query = f"""
        select * from table limit 1
     """

The error changes to:

SYNTAX_ERROR: line 1:8: SELECT * not allowed from relation that has no columns

What haven't I tried? Even just a suggestion of where I can start looking for a solution would help; I've literally spent all of today and last night on this.

Hezza
質問済み 7ヶ月前725ビュー
1回答
0

Hi,

The error message "SYNTAX_ERROR: line 1:8: SELECT * not allowed from relation that has no columns" can be caused by various reasons and the error message is a bit misleading. Please refer the document [1].

The error "COLUMN_NOT_FOUND: line 1:8: SELECT * not allowed ..." typically occurs when (1) the user/role does not have sufficient permissions on the table in Lake Formation. (2) the table's classification is UNKNOWN or the table has no column definitions.

Regrading this error: SYNTAX_ERROR: line 1:8: Column 'column_1' cannot be resolved. This error may also occur when the said column is missing from the Athena data source. If your Data source does have that column and the issue still persists, you can open a support case with AWS Athena team with query ID and region name.

How can I resolve the "SYNTAX_ERROR: line 1:8: SELECT * not allowed in queries without FROM clause" error in Amazon Athena? - [1] https://repost.aws/knowledge-center/athena-syntax-error-select-not-allowed

AWS
回答済み 7ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ