[sqlalchemy] Re: Defining custom types
thatsanicehatyouh...@mac.com wrote: Hello, On 12 Oct 2009, at 21:04, Michael Bayer wrote: On Oct 12, 2009, at 4:26 PM, thatsanicehatyouh...@mac.com wrote: Hello, I have a custom type defined in my postgresql database, and this is giving me the warning: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- packages/sqlalchemy/engine/base.py:1265: SAWarning: Did not recognize type 'fibertype' of column 'fiber_type' self.dialect.reflecttable(conn, table, include_columns) From an earlier email from Michael (13 September 2009), I saw that I can do something like this: sa_major_version = sqlalchemy.__version__[0:3] if sa_major_version == 0.5: from sqlalchemy.databases import postgres postgres.ischema_names['fiber_type'] = fibertype elif sa_major_version == 0.6: from sqlalchemy.dialects.postgresql import base as pg pg.ischema_names['fiber_type'] = fibertype But of course fibertype needs to be defined. How can I define this? The definition in the database is simply: CREATE TYPE fibertype AS ENUM ( 'A', 'B', 'C' ); what happens if you put fibertype: FiberType in the dictionary as well ? all its doing is looking in there for something to use. I'm not sure what you mean here. I take this to mean: postgres.ischema_names['fibertype'] = FiberType but in either case, the value of the dictionary here is undefined. That's the thing I'm unsure of how it's to be defined. Do you mean that it should simply be any value, e.g. postgres.ischema_names['fibertype'] = FiberType ah no it should be either a default type like String or a custom type like a TypeEngine or TypeDecorator subclass of your design. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Defining custom types
Hi Michael, Thanks for clarifying that for me. For anyone interested, this is what I ended up with: from sqlalchemy import String sa_major_version = sqlalchemy.__version__[0:3] if sa_major_version == 0.5: from sqlalchemy.databases import postgres postgres.ischema_names['fibertype'] = String elif sa_major_version == 0.6: from sqlalchemy.dialects.postgresql import base as pg pg.ischema_names['fibertype'] = String Cheers, Demitri On 15 Oct 2009, at 16:06, Michael Bayer wrote: thatsanicehatyouh...@mac.com wrote: Hello, On 12 Oct 2009, at 21:04, Michael Bayer wrote: On Oct 12, 2009, at 4:26 PM, thatsanicehatyouh...@mac.com wrote: Hello, I have a custom type defined in my postgresql database, and this is giving me the warning: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site- packages/sqlalchemy/engine/base.py:1265: SAWarning: Did not recognize type 'fibertype' of column 'fiber_type' self.dialect.reflecttable(conn, table, include_columns) From an earlier email from Michael (13 September 2009), I saw that I can do something like this: sa_major_version = sqlalchemy.__version__[0:3] if sa_major_version == 0.5: from sqlalchemy.databases import postgres postgres.ischema_names['fiber_type'] = fibertype elif sa_major_version == 0.6: from sqlalchemy.dialects.postgresql import base as pg pg.ischema_names['fiber_type'] = fibertype But of course fibertype needs to be defined. How can I define this? The definition in the database is simply: CREATE TYPE fibertype AS ENUM ( 'A', 'B', 'C' ); what happens if you put fibertype: FiberType in the dictionary as well ? all its doing is looking in there for something to use. I'm not sure what you mean here. I take this to mean: postgres.ischema_names['fibertype'] = FiberType but in either case, the value of the dictionary here is undefined. That's the thing I'm unsure of how it's to be defined. Do you mean that it should simply be any value, e.g. postgres.ischema_names['fibertype'] = FiberType ah no it should be either a default type like String or a custom type like a TypeEngine or TypeDecorator subclass of your design. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Defining custom types
On Oct 12, 2009, at 4:26 PM, thatsanicehatyouh...@mac.com wrote: Hello, I have a custom type defined in my postgresql database, and this is giving me the warning: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- packages/sqlalchemy/engine/base.py:1265: SAWarning: Did not recognize type 'fibertype' of column 'fiber_type' self.dialect.reflecttable(conn, table, include_columns) From an earlier email from Michael (13 September 2009), I saw that I can do something like this: sa_major_version = sqlalchemy.__version__[0:3] if sa_major_version == 0.5: from sqlalchemy.databases import postgres postgres.ischema_names['fiber_type'] = fibertype elif sa_major_version == 0.6: from sqlalchemy.dialects.postgresql import base as pg pg.ischema_names['fiber_type'] = fibertype But of course fibertype needs to be defined. How can I define this? The definition in the database is simply: CREATE TYPE fibertype AS ENUM ( 'A', 'B', 'C' ); what happens if you put fibertype: FiberType in the dictionary as well ? all its doing is looking in there for something to use. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---