2017-09-24 66 views
0

我有一个RESTAPI将接受多个业务客户端查询,每次都会有一个份额public架构和私人client_x模式,使用postgresql如何使用sqlalchemy和aiopg动态更改postgresql模式?

尽管每个分离的应用,是有可能在SAConnection动态改变模式?

我想:

async with pool.acquire() as conn: 
    logging.info(self.current_schema) 
    if self.current_schema is not None: 
    proxy = await conn.execute(
     'SET search_path TO {}, public; select current_schemas(true);'.format(self.current_schema)) 
    logging.info('set schema to %s' % (await proxy.fetchone())) 

result: 
2017-09-24 10:50:16.928 __init__:74867 INFO client_1 
2017-09-24 10:50:16.967 __init__:74867 INFO set schema to (['pg_catalog', 'public'],) 

的模式没有改变

回答

0

我的代码实际工作。

问题是我错过拼写模式名称,然后postgresql只是简单地忽略不存在的模式没有错误