【问题标题】:How to create partitioned table from other tables in Amazon Athena?如何从 Amazon Athena 中的其他表创建分区表?
【发布时间】:2021-09-13 17:57:52
【问题描述】:

我希望从 Amazon Athena 中的现有表创建一个表。现有表在 partition_0、partition_1 和 partition_2(所有字符串)上进行分区,我希望这个分区能够继续。这是我的代码:

CREATE TABLE IF NOT EXISTS newTable
AS
Select x, partition_0, partition_1, partition_2 
FROM existingTable T
PARTITIONED BY (partition_0 string, partition_1 string, partition_2 string)

尝试运行它会在 FROM 行出现错误,说 "mismatched input 'by'. expecting: '(', ',',".... Status code: 400; error code:invalidrequestexception
不确定我在这里缺少什么语法。

【问题讨论】:

  • 你试过更简单的吗:PARTITIONED BY partition_0, partition_1 , partition_2

标签: sql amazon-athena create-table partition


【解决方案1】:

这是创建新表的语法:

CREATE TABLE new_table 
WITH (
  format = 'parquet',  
  external_location = 's3://example-bucket/output/', 
  partitioned_by = ARRAY['partition_0', 'partition_1', 'partition_2']) 
AS SELECT * FROM existing_table

有关更多示例,请参阅文档:https://docs.aws.amazon.com/athena/latest/ug/ctas-examples.html#ctas-example-partitioned

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-03
    • 2020-03-19
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    相关资源
    最近更新 更多