MCPcopy
hub / github.com/MagicStack/asyncpg / execute

Method execute

asyncpg/connection.py:314–364  ·  view source on GitHub ↗

Execute an SQL command (or commands). This method can execute many SQL commands at once, when no arguments are provided. Example: .. code-block:: pycon >>> await con.execute(''' ... CREATE TABLE mytab (a int); ... INSERT

(
        self,
        query: str,
        *args,
        timeout: typing.Optional[float]=None,
    )

Source from the content-addressed store, hash-verified

312 return self._protocol.is_in_transaction()
313
314 async def execute(
315 self,
316 query: str,
317 *args,
318 timeout: typing.Optional[float]=None,
319 ) -> str:
320 """Execute an SQL command (or commands).
321
322 This method can execute many SQL commands at once, when no arguments
323 are provided.
324
325 Example:
326
327 .. code-block:: pycon
328
329 >>> await con.execute('''
330 ... CREATE TABLE mytab (a int);
331 ... INSERT INTO mytab (a) VALUES (100), (200), (300);
332 ... ''')
333 INSERT 0 3
334
335 >>> await con.execute('''
336 ... INSERT INTO mytab (a) VALUES ($1), ($2)
337 ... ''', 10, 20)
338 INSERT 0 2
339
340 :param args: Query arguments.
341 :param float timeout: Optional timeout value in seconds.
342 :return str: Status of the last SQL command.
343
344 .. versionchanged:: 0.5.4
345 Made it possible to pass query arguments.
346 """
347 self._check_open()
348
349 if not args:
350 if self._query_loggers:
351 with self._time_and_log(query, args, timeout):
352 result = await self._protocol.query(query, timeout)
353 else:
354 result = await self._protocol.query(query, timeout)
355 return result
356
357 _, status, _ = await self._execute(
358 query,
359 args,
360 0,
361 timeout,
362 return_status=True,
363 )
364 return status.decode()
365
366 async def executemany(
367 self,

Callers 2

_resetMethod · 0.95
resetMethod · 0.95

Calls 3

_check_openMethod · 0.95
_time_and_logMethod · 0.95
_executeMethod · 0.95

Tested by

no test coverage detected