MyTetra Share
Делитесь знаниями!
Работа с объектами UUID в psycopg2
Время создания: 10.12.2019 18:22
Автор: br0ke
Текстовые метки: python, psycopg2, psycopg, postgre, postgres, postgresql, uuid, adapter
Раздел: Информационные технологии - Python - Библиотеки - psycopg2
Запись: and-semakin/mytetra_data/master/base/15759841411rgug2680x/text.html на raw.githubusercontent.com

import psycopg2.extras


# call it in any place of your program

# before working with UUID objects in PostgreSQL

psycopg2.extras.register_uuid()


# now you can pass UUID objects into psycopg2 functions

cursor.execute("INSERT INTO MyTable (uuid) VALUES (%s)", (uuid.uuid4(),))


# ... and even get it from there

cursor.execute("SELECT uuid FROM MyTable")

value, = cursor.fetchone()

assert isinstance(value, uuid.UUID)

 
MyTetra Share v.0.59
Яндекс индекс цитирования