简体   繁体   中英

Create View in Athena but "column name specified more than once"

I have created a SELECT query that joins three tables in AWS Athena - the query itself works...

Select t1.*, t2.*, t3.*
from "analytics_poc"."stg_orderitem" as t1
INNER Join "analytics_poc"."stg_orderitemtag" as t2
ON t1.orderitemid=t2.orderitemid
LEFT Join "analytics_poc"."stg_tag" as t3
ON t3.tagid=t2.tagid

However, when I try to create a VIEW from this query I get this error...

CREATE OR REPLACE VIEW "CMS_orderitem_tags"
AS 
Select t1.*, t2.*, t3.*
from "analytics_poc"."stg_orderitem" as t1
INNER Join "analytics_poc"."stg_orderitemtag" as t2
ON t1.orderitemid=t2.orderitemid
LEFT Join "analytics_poc"."stg_tag" as t3
ON t3.tagid=t2.tagid
line 1:1: Column name 'orderitemid' specified more than once.

Does anyone know why this is the case?

It would appear that a column called orderitemid exists in more than one of those tables.

The SELECT command doesn't mind having multiple output columns with the same name, but CREATE VIEW doesn't allow it.

You could try USING instead, which removes the 'join' column.

Change this line:

INNER Join "analytics_poc"."stg_orderitemtag" as t2 ON t1.orderitemid=t2.orderitemid

into:

INNER Join "analytics_poc"."stg_orderitemtag" as t2 ON USING(orderitemid)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM