On Feb 12, 2012, at 5:22 AM, Krishnakant Mane wrote:
> On 11/02/12 21:10, Michael Bayer wrote:
>> def execproc(procname, engine, queryParams=[]):
>> function = getattr(func, procname)
>> function_with_params = function(*queryParams)
>> return
>> engine.execute(function_with_params.execution_options(autocommit=True))
>>
>
>
> Hi Michael,
> I tryed this code with postgresql (psycopg2 ).
>
> I have a group table with the fields.
> groupcode integer, groupname text and groupdesc text.
>
> When I pass in a procedure name called get groups with all the above listed
> columns as output parameters (actually the procedure returns setof rows), I
> get the could not locate column on the groupcode field.
OK sorry, you want individual columns from the function which means "select *"
from it. Here is that, using a function from postgresql's website:
from sqlalchemy import create_engine, func, select, literal_column
engine = create_engine('postgresql://scott:tiger@localhost/test', echo=True)
engine.execute("""
CREATE OR REPLACE FUNCTION dup(int) RETURNS TABLE(f1 int, f2 text)
AS $$ SELECT $1, CAST($1 AS text) || ' is text' $$
LANGUAGE SQL;
""")
def execproc(procname, engine, queryParams=[]):
function = getattr(func, procname)
function_with_params = function(*queryParams)
return engine.execute(
select([literal_column('*')]).\
select_from(function_with_params).\
execution_options(autocommit=True)
)
for row in execproc("dup", engine, [42]):
print row.f1, row.f2
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.