i try to run mysql functions in sqlalchemy insert().values()
how to set the unit in TIMESTAMPDIFF(unit, ..) or any other str inside a function?
from sqlalchemy.ext.asyncio import create_async_engine
engine = create_async_engine( "mysql+aiomysql://user:passwd@localhost/database1", echo= True )
import sqlalchemy
async with engine.begin() as connection:
result= await connection.execute(
tabel1.insert().values(
utc_offset= sqlalchemy.func.TIMESTAMPDIFF( 'SECOND', sqlalchemy.func.UTC_TIMESTAMP(), sqlalchemy.func.NOW())
)
)
printr( result.inserted_primary_key )
error message
2021-07-10 22:14:06,533 INFO sqlalchemy.engine.Engine INSERT INTO tabel1 (utc_offset) VALUES (TIMESTAMPDIFF(%s, UTC_TIMESTAMP(), now()))
2021-07-10 22:14:06,533 INFO sqlalchemy.engine.Engine [generated in 0.00004s] ('SECOND',)
2021-07-10 22:14:06,533 INFO sqlalchemy.engine.Engine ROLLBACK
ERROR: Exception in ASGI application
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''SECOND', UTC_TIMESTAMP(), now()))' at line 1")
[SQL: INSERT INTO tabel1 (utc_offset) VALUES (TIMESTAMPDIFF(%s, UTC_TIMESTAMP(), now()))]
[parameters: ('SECOND',)]
(Background on this error at: http://sqlalche.me/e/14/f405)