MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / copy_to_table

Method copy_to_table

asyncpg/connection.py:963–1049  ·  view source on GitHub ↗

Copy data to the specified table. :param str table_name: The name of the table to copy data to. :param source: A :term:`path-like object `, or a :term:`file-like object `, or an :term:

(self, table_name, *, source,
                            columns=None, schema_name=None, timeout=None,
                            format=None, oids=None, freeze=None,
                            delimiter=None, null=None, header=None,
                            quote=None, escape=None, force_quote=None,
                            force_not_null=None, force_null=None,
                            encoding=None, where=None)

Source from the content-addressed store, hash-verified

961 return await self._copy_out(copy_stmt, output, timeout)
962
963 async def copy_to_table(self, table_name, *, source,
964 columns=None, schema_name=None, timeout=None,
965 format=None, oids=None, freeze=None,
966 delimiter=None, null=None, header=None,
967 quote=None, escape=None, force_quote=None,
968 force_not_null=None, force_null=None,
969 encoding=None, where=None):
970 """Copy data to the specified table.
971
972 :param str table_name:
973 The name of the table to copy data to.
974
975 :param source:
976 A :term:`path-like object <python:path-like object>`,
977 or a :term:`file-like object <python:file-like object>`, or
978 an :term:`asynchronous iterable <python:asynchronous iterable>`
979 that returns ``bytes``, or an object supporting the
980 :ref:`buffer protocol <python:bufferobjects>`.
981
982 :param list columns:
983 An optional list of column names to copy.
984
985 :param str schema_name:
986 An optional schema name to qualify the table.
987
988 :param str where:
989 An optional SQL expression used to filter rows when copying.
990
991 .. note::
992
993 Usage of this parameter requires support for the
994 ``COPY FROM ... WHERE`` syntax, introduced in
995 PostgreSQL version 12.
996
997 :param float timeout:
998 Optional timeout value in seconds.
999
1000 The remaining keyword arguments are ``COPY`` statement options,
1001 see `COPY statement documentation`_ for details.
1002
1003 :return: The status string of the COPY command.
1004
1005 Example:
1006
1007 .. code-block:: pycon
1008
1009 >>> import asyncpg
1010 >>> import asyncio
1011 >>> async def run():
1012 ... con = await asyncpg.connect(user='postgres')
1013 ... result = await con.copy_to_table(
1014 ... 'mytable', source='datafile.tbl')
1015 ... print(result)
1016 ...
1017 >>> asyncio.run(run())
1018 'COPY 140000'
1019
1020 .. _`COPY statement documentation`:

Callers

nothing calls this directly

Calls 3

_format_copy_whereMethod · 0.95
_format_copy_optsMethod · 0.95
_copy_inMethod · 0.95

Tested by

no test coverage detected