diff --git a/duckdb_engine/__init__.py b/duckdb_engine/__init__.py index 38745702..d3fa4715 100644 --- a/duckdb_engine/__init__.py +++ b/duckdb_engine/__init__.py @@ -137,6 +137,7 @@ def execute( else: raise e +from sqlalchemy.dialects.postgresql import UUID class DuckDBEngineWarning(Warning): pass @@ -160,6 +161,7 @@ class Dialect(PGDialect_psycopg2): sqltypes.Numeric: sqltypes.Numeric, sqltypes.Interval: sqltypes.Interval, sqltypes.JSON: sqltypes.JSON, + UUID: UUID }, ) diff --git a/duckdb_engine/tests/test_datatypes.py b/duckdb_engine/tests/test_datatypes.py index 94dd230f..c2c1c51e 100644 --- a/duckdb_engine/tests/test_datatypes.py +++ b/duckdb_engine/tests/test_datatypes.py @@ -1,11 +1,13 @@ from typing import Type +from uuid import uuid4 from pytest import mark from sqlalchemy import Column, Integer from sqlalchemy.engine import Engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session from sqlalchemy.types import JSON +from sqlalchemy.dialects.postgresql import UUID from ..datatypes import types @@ -52,3 +54,23 @@ class Entry(base): result = session.query(Entry).one() assert result.meta == {"hello": "world"} + + +def test_uuid(engine: Engine, session: Session) -> None: + base = declarative_base() + + class Entry(base): + __tablename__ = "test_uuid" + + id = Column(UUID, primary_key=True, default=0) + + base.metadata.create_all(bind=engine) + + ident = uuid4() + + session.add(Entry(id=(ident))) + session.commit() + + result = session.query(Entry).one() + + assert result.id == ident