Is there any function avaliable in greenplum to generate UUID

897 views Asked by At

Is there any way to generate UUID in Greenplum. As latest version of Greenplum is using Postgres 8.2 and this feature is not available for Postgres 8.2 (used by Greenplum), but the same has been added to later versions of Postgres . Is there any way we can populate column with UUID in greenplum?

1

There are 1 answers

0
Mike On

You could just write it in PL/Python, since Python's uuid library makes this easy (I'm assuming a random UUID, and that you can run this as "gpadmin"):

CREATE OR REPLACE FUNCTION UUID ()
RETURNS VARCHAR(36)
AS $$
import uuid
return str(uuid.uuid4())
$$ LANGUAGE plpythonu;

Now (still as gpadmin):

gpadmin=# select UUID() from generate_series(1, 10);
                 uuid
--------------------------------------
 476f35e4-da1a-43cf-8f7c-950ac71d4848
 71db22ed-ff6f-4615-a877-db803b474ae7
 6584670a-ab4d-44c5-b854-7e19e66d4738
 ed174b1f-0b61-48df-bdec-60146e063d74
 bb643e3e-5d7f-4382-b415-0145cd2bca99
 d4c784f7-1baa-4869-b9a8-d6cf6dce0cba
 79e65c0f-9573-4d94-8c9a-f894ec096643
 bf8dd0da-e1dd-4604-851d-01b0ac8793c3
 b80180de-d342-456f-952f-1ca2cbcce4e4
 f752ed61-d71a-4835-ac12-8e66132ba351
(10 rows)

Time: 1.902 ms