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)