0

I want to concat the table name with the lastDay date as a string, and have this kind of results :

dl-recommendation-engine:NDA_CHANEL_137002018.ga_sessions_20200128

I found this line to get me the day of yesterday

REPLACE(CAST(DATE_SUB(DATE_TRUNC(CURRENT_DATE(), DAY), INTERVAL 1 DAY) as STRING), "-","") I casted it as a string

But now I have to concat all and it doesn't work ...

date,
transaction.transactionId, 
ref.productSKU as productRef, 
associated.productSKU as productAssociated, 
ARRAY_LENGTH(hits.product) as nbProducts

FROM CONCAT("`dl-recommendation-engine:NDA_CHANEL_137002018.ga_sessions_",
REPLACE(CAST(DATE_SUB(DATE_TRUNC(CURRENT_DATE(), DAY), INTERVAL 1 DAY) as STRING), "-",""),
"`") as session,

UNNEST(hits) AS hits,
UNNEST(hits.product) as ref,
UNNEST(hits.product) as associated

AND hits.transaction.transactionId IS NOT NULL
AND ARRAY_LENGTH(hits.product) > 2```

1
  • 2
    You can't do this without using dynamic SQL to execute the query. Commented Jan 29, 2020 at 12:55

1 Answer 1

2

Why don't you use _TABLE_SUFFIX?

I simplified the query by deleting unnecessary columns here:

SELECT *
FROM `dl-recommendation-engine:NDA_CHANEL_137002018.ga_sessions_*` as session,
WHERE 
_TABLE_SUFFIX = FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY))
Sign up to request clarification or add additional context in comments.

1 Comment

Yes that's what i did finally , thank you very much :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.