psycopg2: Can't adapt type 'UUID'? psycopg2: Can't adapt type 'UUID'? python-3.x python-3.x

psycopg2: Can't adapt type 'UUID'?


As author noted in comments, to pass UUID objects into cursor methods one have to call register_uuid() first once:

import psycopg2.extras# call it in any place of your program# before working with UUID objects in PostgreSQLpsycopg2.extras.register_uuid()# now you can pass UUID objects into psycopg2 functionscursor.execute("INSERT INTO MyTable (uuid) VALUES (%s)", (uuid.uuid4(),))# ... and even get it from therecursor.execute("SELECT uuid FROM MyTable")value, = cursor.fetchone()assert isinstance(value, uuid.UUID)


uuid_entry = str(uuid.uuid4()) 

This works for me. Not sure if it is the right approach.