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달 전722회 조회
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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인