如何在redshift中生成12位唯一数字? [英] How to generate 12 digit unique number in redshift?

查看:171
本文介绍了如何在redshift中生成12位唯一数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表中有3列,即 email_id rid final_id

I have 3 columns in a table i.e. email_id, rid, final_id.

rid final_id


  1. 如果 email_id 具有相应的 rid ,将 rid 用作 final_id

  2. 如果 email_id 没有相应的 rid (即 rid 为空),生成一个唯一的12位数字,然后插入 final_id 字段。

  1. If the email_id has a corresponding rid, use rid as the final_id.
  2. If the email_id does not have a corresponding rid(i.e.rid is null), generate a unique 12 digit number and insert into final_id field.

如何在redshift中生成12位唯一数字?

How to generate 12 digit unique number in redshift?

推荐答案

来自在Redshift中创建UUID函数


默认AWS Redshift中没有UUID函数。但是,使用 Python用户定义函数,您可以在Redshift中轻松创建UUID函数。

By default there is no UUID function in AWS Redshift. However with the Python User-Defined Function you can easily create a UUID function in Redshift.

如果您需要随机UUID:

If you want random UUID:



CREATE OR REPLACE FUNCTION public.fn_uuid()
RETURNS character varying AS
' import uuid
 return uuid.uuid4().__str__()
 '
LANGUAGE plpythonu VOLATILE;




如果要使用顺序UUID:

If you want sequential UUID :



CREATE OR REPLACE FUNCTION public.fn_uuid()
RETURNS character varying AS
' import uuid
 return uuid.uuid1().__str__()
 '
LANGUAGE plpythonu VOLATILE;

这篇关于如何在redshift中生成12位唯一数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆