最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

postgresql - How to generate Guid for each row with select statement only - Stack Overflow

programmeradmin3浏览0评论

I am trying to with a select statement generate a unique guid for each row. I tried this but the guid is the same so don't have this correct yet.

select * from tblCustomer, (select gen_random_uuid() as newId)

I am trying to with a select statement generate a unique guid for each row. I tried this but the guid is the same so don't have this correct yet.

select * from tblCustomer, (select gen_random_uuid() as newId)
Share Improve this question edited Mar 17 at 16:06 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 17 at 16:05 beantownacebeantownace 1372 silver badges12 bronze badges 2
  • Is this guid based on the row's content, or just a unique random ID? gen_random_uuid is a uuid v4, also exists the serials and something like "select md5(f::text) FROM f" – Frank N Stein Commented Mar 17 at 17:16
  • Why do you even use a subquery for this? – Frank Heikens Commented Mar 17 at 17:44
Add a comment  | 

1 Answer 1

Reset to default 5

This is happening because you're generating newId in a subquery; there's no reason to do this.

Here's what you want instead:

SELECT *,
       gen_random_uuid() AS newId
  FROM tblCustomer;

I've spread it over three lines here to clearly delineate how the query is structured, but you can keep it on one line if you prefer.

发布评论

评论列表(0)

  1. 暂无评论