Re: Can't register python class for domain?
| От | W. Matthew Wilson |
|---|---|
| Тема | Re: Can't register python class for domain? |
| Дата | |
| Msg-id | CAGHfCUDzR6O8C7ved0vSbuozqJB+658p8zeC8DdyTx+am_jeBA@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Can't register python class for domain? (Adrian Klaver <adrian.klaver@aklaver.com>) |
| Список | psycopg |
Here's the class I want to register:
class Milliamp(numbers.Real):
def __init__(self, val):
self.val = val
@classmethod
def adapt_from_pg(cls, value, cursor):
log.debug("Inside adapt_from_pg and value is {0}.".format(value))
if value is None:
return
else:
return cls(value)
Here's how I try to register it:
from dazzle.dazzletypes import Milliamp
MILLIAMP = psycopg2.extensions.new_type(
(milliamp_oid, ),
"milliamp",
Milliamp.adapt_from_pg)
psycopg2.extensions.register_type(MILLIAMP)
I look up the milliamp OID by querying the pg_type table:
> select typname, oid from pg_type where typname in ('float8', 'milliamp');
typname oid
-------- ------
float8 701
milliamp 949531
(2 rows)
В списке psycopg по дате отправления: