【问题标题】:How to write multiple SQL statements like CREATE table in AWS Athena ( using CLI command - aws athena start-query-execution --query-string {value} )?如何在 AWS Athena 中编写多个 SQL 语句,如 CREATE 表(使用 CLI 命令 - aws athena start-query-execution --query-string {value} )?
【发布时间】:2019-07-02 06:50:12
【问题描述】:

如何编写多条CREATE TABLE语句通过ATHENA CLI命令- aws athena start-query-execution执行多条SQL语句

我已经尝试过了,但只使用了一条 SQL 语句,它工作正常。但是我需要运行多个 SQL 语句

( select count(*) from elb_logs; create external table tbl_nm; ) 通过 CLI Athena 命令。

aws athena start-query-execution \
   --query-string "select count(*) from elb_logs;" \
   --query-execution-context Database=default \
   --result-configuration OutputLocation=s3://aws-athena-query-results-xxxxxxxxxx-us-east-1/ \
   --region us-east-1 \
   --output text

应该能够通过 CLI 命令在 AWS Athena 上执行多个 SQL 语句。

【问题讨论】:

    标签: sql amazon-web-services amazon-athena execution statements


    【解决方案1】:

    我认为您不能在一个 CLI 命令中运行多个查询,我刚刚尝试并收到此错误:

        An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: 
        Only one sql statement is allowed.
    

    一一运行。

    【讨论】:

    • 我在 AWS 文档中读到它提供了运行多个 SQL 语句的能力,但限制为 20 个 SQL 语句,可以通过 CLI 运行,但我只是坚持编写多个语句的正确语法。 aws athena start-query-execution \ --query-string "select count(*) from elb_logs;" \
    • @Deep 您可以添加指向此文档的链接吗?
    • 如果您阅读了docs.aws.amazon.com/cli/latest/reference/athena/… 的 AWS 文档,您可以在描述中找到“运行查询中包含的 SQL 查询语句”。可以运行的 SQL 语句默认限制为 20 条 docs.aws.amazon.com/athena/latest/ug/service-limits.html
    • 这个限制意味着你可以运行 20 个并发执行(同时运行的查询),而不是你可以在同一个请求中传递 20 个语句。每个 StartQueryExecution 调用只能有一个语句。
    • 我从 AWS 支持团队得到确认,我们只能在 Athena 中提交一个查询,并且无法并行运行多个 DDL 语句。请不要将这与 Athena 服务限制 [1] 混淆,后者指定了 20 次 StartQueryExecution 调用以及默认的 20 次 DML 和 20 次 DDL 查询可以同时进行。这只是意味着可以进行 20 个并发调用,但每个调用中只能包含一个查询。因此,您可能有多个系统进行 Athena 查询,但同时进行的查询数量限制为 20 个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    • 2021-05-26
    • 2019-03-22
    • 2021-12-22
    相关资源
    最近更新 更多