Hi,

The following function (bugfn) gives errors when I try to execute it with 
postgresql using sqlalchemy.sql's text function. I thought the problem was 
with using double quotes (") and/or single quotes (') inside the string, 
but no, it seems to be perfectly happy with sex_sub for example.

Executing bugfn directly in psql works fine, so it is not a postgres 
problem.

Traceback follows. If I need to submit an issue, let me know. Please cc me 
on any reply.

                                                     Regards, Faheem Mitha.

***************************************************************************
Traceback (most recent call last):
   File "dbsession.py", line 260, in <module>
     make_tables(dbstring)
   File "dbsession.py", line 146, in make_tables
     conn.execute(create_bug_function)
   File "/var/lib/python-support/python2.5/sqlalchemy/engine/base.py", line 
806, in execute
     return Connection.executors[c](self, object, multiparams, params)
   File "/var/lib/python-support/python2.5/sqlalchemy/engine/base.py", line 
856, in execute_clauseelement
     return self.__execute_context(context)
   File "/var/lib/python-support/python2.5/sqlalchemy/engine/base.py", line 
878, in __execute_context
     self._cursor_execute(context.cursor, context.statement, 
context.parameters[0], context=context)
   File "/var/lib/python-support/python2.5/sqlalchemy/engine/base.py", line 
925, in _cursor_execute
     self.dialect.do_execute(cursor, statement, parameters, 
context=context)
   File "/var/lib/python-support/python2.5/sqlalchemy/engine/default.py", 
line 122, in do_execute
     cursor.execute(statement, parameters)
TypeError: 'dict' object is unindexable
************************************************************************

from sqlalchemy.sql import text

create_plpython = text("""
CREATE LANGUAGE plpythonu;
""")

create_bug_function = text("""
CREATE OR REPLACE FUNCTION bugfn (sex text)
RETURNS integer
AS $$
     if sex == 'F':
         return 2
     else:
         raise RuntimeError, "%s is wrong"%(sex)
     $$ LANGUAGE plpythonu;
""")

create_sex_sub_function = text("""
CREATE OR REPLACE FUNCTION sex_sub (sex text)
RETURNS integer
AS $$
     if sex == 'M':
         return 1
     if sex == 'F':
         return 2
     else:
         raise RuntimeError, "sex must be either 'M' or 'F' but is '" + sex + 
"'."
     $$ LANGUAGE plpythonu;
""")

  [...]
  db = create_engine("postgres://btsnp:foo...@localhost:5432/btsnp_test")
  conn = db.connect()
  conn.execute(create_plpython)
  conn.execute(create_sex_sub_function)
  conn.execute(create_bug_function)
  conn.close()

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to