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
1 Answer
Reset to default 5This 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.