Hi Guys I am a Python newbie, so as my first project I decided to port a relatively simple (320 lines) Perl script I wrote to Python to see how it compared. I asked on the #python irc channel and they recommended I use sqlalchemy which I how I ended up here. I am trying to do the following (which appears to be correct as far as I can tell):
db = create_engine('postgres://' + Dbuser + ':' + Dbpass + '@' + Dbhost + ':' + Dbport + '/' + database) db.echo = True metadata = BoundMetaData(db) radacct_table = Table('radacct', metadata, autoload=True) However I end up with the following ugly error: 2007-01-16 12:52:24,366 INFO sqlalchemy.engine.base.Engine.0x..cc select current_schema() 2007-01-16 12:52:24,367 INFO sqlalchemy.engine.base.Engine.0x..cc None 2007-01-16 12:52:24,374 INFO sqlalchemy.engine.base.Engine.0x..cc SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod), (SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS DEFAULT, a.attnotnull, a.attnum FROM pg_catalog.pg_attribute a WHERE a.attrelid = ( SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE (n.nspname = %(schema)s OR pg_catalog.pg_table_is_visible(c.oid)) AND c.relname = %(table_name)s AND (c.relkind = 'r' OR c.relkind = 'v') ) AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum 2007-01-16 12:52:24,377 INFO sqlalchemy.engine.base.Engine.0x..cc {'table_name': 'radacct', 'schema': 'public'} Traceback (most recent call last): File "./radsqlkill.py", line 145, in <module> db_connect('localhost'); File "./radsqlkill.py", line 80, in db_connect radacct_table = Table('radacct', metadata, autoload=True) File "/usr/lib/python2.5/site-packages/sqlalchemy/schema.py", line 143, in __call__ metadata.get_engine().reflecttable(table) File "/usr/lib/python2.5/site-packages/sqlalchemy/engine/base.py", line 505, in reflecttable self.dialect.reflecttable(conn, table) File "/usr/lib/python2.5/site-packages/sqlalchemy/databases/postgres.py", line 385, in reflecttable coltype = ischema_names[attype] KeyError: 'inet' Now this seems to be related to the fact that I am using INET field types in my table. While I could convert my data its a 2GB+ table and the INET field types make a BIG difference in speed and usability (I have extensive reporting based on them) I have the following: # rpm -q python python-2.5-19.2 # rpm -q python-sqlalchemy python-sqlalchemy-0.3.3-0.pm.1 # rpm -q python-psycopg2 python-psycopg2-2.0.2-10.1 Is there some way to make this work or do I need to go an find another database library to use Postgresql INET types with Python? Cheers -- Peter Nixon http://www.peternixon.net/ PGP Key: http://www.peternixon.net/public.asc
pgpjoEKtC0XSY.pgp
Description: PGP signature