Comments (16)

there's a wide range of types that fall under this category, where we would be tasked implementing string formatting for every possible type of value. while dates are very common and are on the borderline here, I can't see myself getting involved with formatting every kind of value, like PG INTERVAL, arrays, BLOBs, and everything else, into raw SQL. The reason this works for you without --sql is because the DBAPI handles it. SQLAlchemy really does not want to get into duplicating all that behavior, and that's why that NotImplementedError you're getting is quite intentional.

So while I can *maybe* bend on dates here, for now you need to format those dates yourself in the way MySQL wants, using literal_column (note I'm not certain this is the exact format):

literal_column(mydate.strftime("%Y-%m-%d"))

also the fix here is in SQLAlchemy, but I'll leave it over here as it's an alembic-only use case.

OK well this is the mechanics of bulk_insert() and it would need to be enhanced to support the acceptance of non-parameter elements, which is tricky because in non-SQL mode, everything needs to be sent as a bind since we are using executemany(). one moment please

inline_literal() should be accepted directly here and that is fixed in #179. Your bulk_insert() with inline_literal() will work as-is in --sql mode. In "online" mode, you now have to sent bulk_insert() a clue that it needs to invoke individual INSERT statements by passing the new flag multiinsert:

Mike, sorry I noticed I used the wrong forum for this. See it is for alembic.. but it's all SQLAlchemy ;)

I did work around it after some playing around. Finally came up with extending the TypeDecorator for Date, giving it a literal processor, then checking if the val on the right of a BinaryExpression is Date, and inject the other instance. It's kind of a monkey patch but it works, since I'm only using it for unit testing. Obviously I'd need to do this for any expression that could potentially have a date....

ifisinstance(arg,ClauseElement):ifisinstance(arg,BinaryExpression)andisinstance(arg.right.type,sqlalchemy.sql.sqltypes.Date):arg.right.type=_LiteralDate()expr=str(arg.compile(compile_kwargs={"literal_binds":True}))# print(expr, flush=True) # Use this to see what expressions are getting compiled.returnexpr