--- /dev/null
+.. change::
+ :tags: bug, postgresql
+ :tickets: 4016
+
+ Enabled UUID support for the pg8000 driver, which supports native Python
+ uuid round trips for this datatype. Arrays of UUID are still not supported,
+ however.
\ No newline at end of file
from ... import types as sqltypes
from .base import (
PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext,
- _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES)
+ _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES, UUID)
import re
from sqlalchemy.dialects.postgresql.json import JSON
from ...sql.elements import quoted_name
+try:
+ from uuid import UUID as _python_UUID
+except ImportError:
+ _python_UUID = None
+
class _PGNumeric(sqltypes.Numeric):
def result_processor(self, dialect, coltype):
return super(_PGJSON, self).result_processor(dialect, coltype)
+class _PGUUID(UUID):
+ def bind_processor(self, dialect):
+ if not self.as_uuid:
+ def process(value):
+ if value is not None:
+ value = _python_UUID(value)
+ return value
+ return process
+
+ def result_processor(self, dialect, coltype):
+ if not self.as_uuid:
+ def process(value):
+ if value is not None:
+ value = str(value)
+ return value
+ return process
+
+
class PGExecutionContext_pg8000(PGExecutionContext):
pass
sqltypes.Numeric: _PGNumericNoBind,
sqltypes.Float: _PGNumeric,
JSON: _PGJSON,
- sqltypes.JSON: _PGJSON
+ sqltypes.JSON: _PGJSON,
+ UUID: _PGUUID
}
)
'postgresql+zxjdbc',
'column "data" is of type uuid but expression '
'is of type character varying')
- @testing.fails_on('postgresql+pg8000', 'No support for UUID type')
def test_uuid_string(self):
import uuid
self._test_round_trip(
'postgresql+zxjdbc',
'column "data" is of type uuid but expression is '
'of type character varying')
- @testing.fails_on('postgresql+pg8000', 'No support for UUID type')
def test_uuid_uuid(self):
import uuid
self._test_round_trip(
@testing.fails_on('postgresql+zxjdbc',
'column "data" is of type uuid[] but '
'expression is of type character varying')
- @testing.fails_on('postgresql+pg8000', 'No support for UUID type')
+ @testing.fails_on('postgresql+pg8000', 'No support for UUID with ARRAY')
def test_uuid_array(self):
import uuid
self._test_round_trip(
@testing.fails_on('postgresql+zxjdbc',
'column "data" is of type uuid[] but '
'expression is of type character varying')
- @testing.fails_on('postgresql+pg8000', 'No support for UUID type')
+ @testing.fails_on('postgresql+pg8000', 'No support for UUID with ARRAY')
def test_uuid_string_array(self):
import uuid
self._test_round_trip(