Skip to content

Commit 98c7455

Browse files
author
James William Pye
committed
Apply Elvis Pranskevichus' uuid patch.
1 parent ab0a8da commit 98c7455

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

postgresql/protocol/typio.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
time64_noday_io
3737
long-long based time I/O with noday-intervals.
3838
"""
39+
import uuid
3940
import warnings
4041
import codecs
4142
from ..encodings import aliases as pg_enc_aliases
@@ -266,6 +267,13 @@ def circle_unpack(x):
266267
x = ts.circle_unpack(x)
267268
return pg_types.circle(((x[0], x[1]), x[2]))
268269

270+
def uuid_pack(x):
271+
if isinstance(x, uuid.UUID):
272+
return x.bytes
273+
return uuid.UUID(x).bytes
274+
def uuid_unpack(x):
275+
return uuid.UUID(bytes=x)
276+
269277
##
270278
# numeric is represented using:
271279
# ndigits, the number of *numeric* digits.
@@ -419,6 +427,8 @@ def numeric_unpack(x):
419427
pg_types.BOXOID : (box_pack, box_unpack),
420428
pg_types.LSEGOID : (lseg_pack, lseg_unpack),
421429
pg_types.CIRCLEOID : (circle_pack, circle_unpack),
430+
431+
pg_types.UUIDOID : (uuid_pack, uuid_unpack),
422432
}
423433

424434
oid_to_io[pg_types.CIDROID] = (None, None)

postgresql/test/test_driver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import time
1111
import datetime
1212
import decimal
13+
import uuid
1314
from itertools import chain, islice
1415
from operator import itemgetter
1516

@@ -268,6 +269,10 @@
268269
pg_types.varbit('010111101111'),
269270
],
270271
),
272+
('uuid', [
273+
uuid.uuid1(),
274+
],
275+
),
271276
]
272277

273278
if False:

0 commit comments

Comments
 (0)