SQL convert uuid
create function to_uuid(entity_id character varying, OUT uuid_id uuid) returns uuid
language plpgsql
as
B
E
G
I
N
u
u
i
d
i
d
:
=
s
u
b
s
t
r
i
n
g
(
e
n
t
i
t
y
i
d
,
8
,
8
)
∣
∣
′
−
′
∣
∣
s
u
b
s
t
r
i
n
g
(
e
n
t
i
t
y
i
d
,
4
,
4
)
∣
∣
′
−
1
′
∣
∣
s
u
b
s
t
r
i
n
g
(
e
n
t
i
t
y
i
d
,
1
,
3
)
∣
∣
′
−
′
∣
∣
s
u
b
s
t
r
i
n
g
(
e
n
t
i
t
y
i
d
,
16
,
4
)
∣
∣
′
−
′
∣
∣
s
u
b
s
t
r
i
n
g
(
e
n
t
i
t
y
i
d
,
20
,
12
)
;
E
N
D
;
BEGIN uuid_id := substring(entity_id, 8, 8) || '-' || substring(entity_id, 4, 4) || '-1' || substring(entity_id, 1, 3) || '-' || substring(entity_id, 16, 4) || '-' || substring(entity_id, 20, 12); END;
BEGINuuidid:=substring(entityid,8,8)∣∣′−′∣∣substring(entityid,4,4)∣∣′−1′∣∣substring(entityid,1,3)∣∣′−′∣∣substring(entityid,16,4)∣∣′−′∣∣substring(entityid,20,12);END;;
alter function to_uuid(varchar, out uuid) owner to postgres;