asyncpg:如何构造带有参数的 SET 字符串

asyncpg: How to construct SET strings with parameters

在 SET 查询中传递参数的正确方法是什么?

这将 return asyncpg.exceptions.PostgresSyntaxError: syntax error at or near ""

import asyncio

import asyncpg


async def main():
    conn = await asyncpg.connect(user="xx", password="yy", host="127.0.0.1", database="my_db")

    # works
    await conn.execute("select ", "1")

    identity = "arn:aws:sts::123456:assumed-role/thing_1"

    # fails
    await conn.execute("set session iam.identity = ", identity)

asyncio.run(main())

asyncpg 有一个函数:

await conn.execute("select set_config('iam.identity', , false)", identity)