I have a stored procedure on MSSQL server, "prc_add_names", that takes a table-value parameter. The parameter itself is of a custom type "StringTable" defined like so:
CREATE TYPE [dbo].[StringTable] AS TABLE([strValue] [nvarchar](max) NULL)
I have no idea how to execute this procedure using SQLAlchemy. I am used to calling procedures with arguments using session.execute
like this:
result = session.execute('prc_do_something :pArg', {pArg:'foo'})
However, this does not work if I simply pass a list of strings as the argument:
result = session.execute('prc_add_names :pArg', {pArg: ['Name One', 'Name Two']})
which leads to:
sqlalchemy.exc.ProgrammingError: (pymssql.ProgrammingError) (102, "Incorrect syntax near 'Name One'.DB-Lib error message 20018, severity 15:
General SQL Server error: Check messages from the SQL Server
") [SQL: 'prc_add_names %(pArg)s'] [parameters: {'pArg': ['Name One', 'Name Two']}] (Background on this error at: http://sqlalche.me/e/f405)
Obviously, SQLAlchemy does not understand my list of strings as an attempt to create my StringTable-type argument, but after a couple hours of googling and reading through the documentation, I haven't figured out how I should be handling this.
FYI, I am not in control of this database, so modifying the stored procedure or anything else there is not an option.
EDIT: I'm not married to SQLAlchemy. If there is another library that can handle this, I'd be happy to use it instead.