“set session” in a SQLAlchemy session object

后端 未结 3 2162
无人共我
无人共我 2021-01-19 08:20

I\'m using SQLAlchemy for a project, and need to be able to specify a session variable/setting for one specific call for performance reasons:

set session max         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 08:42

    None of the above worked for me. but this worked:

    engine_type: str = 'mysql+mysqlconnector'
    db_user_name: str = ''
    db_user_password: str = ''
    db_server: str = ''
    db_name: str = ''
    engine: sqlalchemy.engine.Engine = create_engine(
       f'{engine_type}://{db_user_name}:{db_user_password}@{db_server}:3306/{db_name}'
    )
    engine.execute("SHOW VARIABLES like 'group_concat_max_len'").fetchone()
    ('group_concat_max_len', '1024')
    engine.execute("SET SESSION group_concat_max_len=10240")
    engine.execute("SHOW VARIABLES like 'group_concat_max_len'").fetchone()
    ('group_concat_max_len', '10240')
    

    this must happen right before the query is performed.

提交回复
热议问题