How to assign a Unique Id for each Row (ROWNUM or ROWID) in Google Bigquery

Often in your data tables you might want to add a unique role identifier. Similar to having your ROWNUM or ROWID in Oracle. Most Users typically use the row number function to generate a unique ID for each row. when you try to do this for large datasets, it thows the below error:

Resources exceeded during query execution: The query could not be 
executed in the allotted memory. OVER() operator used too much memory..

Solution:

Use generate UUID function. This function will automatically generate a random string for each row, thereby making the row unique

SELECT GENERATE_UUID();

c652e249-cc82-4e07-87b9-c63d501d490e

Ryan-Dallas

posted on 10 Mar 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds