Advertisement
Guest User

Tagban's Final Query GBQ

a guest
Apr 5th, 2024
261
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.27 KB | None | 0 0
  1. EXECUTE IMMEDIATE(
  2.   SELECT string_agg(  
  3.       CONCAT("select id, firstName, otherColumns from project.database." , table_id, " ")
  4.       , "UNION ALL \n"
  5.    )
  6. FROM `project.database.__TABLES__`
  7. WHERE table_id LIKE 'LeadingTableName%' AND table_id NOT LIKE '%soupSucks'
  8. )
Advertisement
Comments
  • tagban
    1 year
    # text 0.50 KB | 0 0
    1. This was needed because a 3rd party software we use generates a brand new table in Google Big Query everytime with the exact same schema. This allows us to join the most recent ones (ALL in the version above) and lets us have it all in one 'view' essentially thru a query.
    2.  
    3. There are likely better ways to do this, but I spent about 2 days working on this and wanted to make sure if someone else needs to JOIN DYNAMICALLY named tables in Google Big Query, they have a good starting point. Have a great 2024!
Add Comment
Please, Sign In to add comment
Advertisement