I am trying to call a stored procedure with sqlalchemy to a microsoft sql server. The procedure takes a custom table valued parameter and returns back multiple tables.
The only way to send a TVP i found that is working is using this code that I found online and uses pyodbc in sqlalchemy for the connection.
data = {"tvp": [("foo",1), ("bar",2)]}
sql = f"{{CALL testtypeprocedure ( :tvp)}}"
print(conn.execute(sqlalchemy.text(sql), data).fetchall())
While it manages to send the TVP and execute the procedure it only returns to python the first table that the stored procedure selects.
one way to get back multiple tables that i found is using this type of code.
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc(procedure_name, [param1,param2])
cursor.nextset()
cursor.fetchall()
and this works only when I am using pymssql in sqlalchemy to make the connection, but i cant find a way to send a TVP this way.
Is there any way to do both with either pyodbc or pymssql in sqlalchemy?
(data,)