How to add an integer unique id to query results - __efficiently__?

后端 未结 4 448
面向向阳花
面向向阳花 2021-01-25 17:08

Given a query, select * from ... (that might be part of CTAS statement)

The goal is to add an additional column, ID, where ID is a

4条回答
  •  轮回少年
    2021-01-25 18:03

    If you are using Spark-sql your best bet would be to use the inbuilt function

    monotonically_increasing_id

    which generates unique random id in a separate column. And as you said you don't need it to be sequential so this should ideally suffice your requirement.

提交回复
热议问题