@@ -112,12 +112,38 @@ def transaction(self, *, isolation='read_committed', readonly=False,
112112 """
113113 return transaction .Transaction (self , isolation , readonly , deferrable )
114114
115- async def execute (self , script : str , * , timeout : float = None ) -> str :
115+ async def execute (self , query : str , * args , timeout : float = None ) -> str :
116116 """Execute an SQL command (or commands).
117117
118+ This method can execute many SQL commands at once, when no arguments
119+ are provided.
120+
121+ Example:
122+
123+ .. code-block:: pycon
124+
125+ >>> await con.execute('''
126+ ... CREATE TABLE mytab (a int);
127+ ... ''')
128+ CREATE TABLE
129+
130+ >>> await con.execute('''
131+ ... INSERT INTO mytab (a) VALUES ($1), ($2)
132+ ... ''', 10, 20)
133+ INSERT 0 2
134+
135+ :param args: Query arguments.
136+ :param float timeout: Optional timeout value in seconds.
118137 :return str: Status of the last SQL command.
119138 """
120- return await self ._protocol .query (script , timeout )
139+ if not args :
140+ return await self ._protocol .query (query , timeout )
141+
142+ stmt = await self ._get_statement (query , timeout )
143+ protocol = self ._protocol
144+ _ , status , _ = await protocol .bind_execute (stmt , args , '' , 0 ,
145+ True , timeout )
146+ return status .decode ()
121147
122148 async def _get_statement (self , query , timeout ):
123149 cache = self ._stmt_cache_max_size > 0
0 commit comments