From: | "W(dot) Matthew Wilson" <matt(at)tplus1(dot)com> |
---|---|
To: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
Cc: | "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org> |
Subject: | Re: Can't register python class for domain? |
Date: | 2015-01-23 15:31:44 |
Message-ID: | CAGHfCUDzR6O8C7ved0vSbuozqJB+658p8zeC8DdyTx+am_jeBA@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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)
From | Date | Subject | |
---|---|---|---|
Next Message | W. Matthew Wilson | 2015-01-23 15:39:46 | Re: Can't register python class for domain? |
Previous Message | Daniele Varrazzo | 2015-01-23 15:29:07 | Re: Can't register python class for domain? |