Copy a list of records to the specified table using binary COPY. :param str table_name: The name of the table to copy data to. :param records: An iterable returning row tuples to copy into the table. :term:`Asynchronous iterables <python:asynchro
(self, table_name, *, records,
columns=None, schema_name=None,
timeout=None, where=None)
| 1049 | return await self._copy_in(copy_stmt, source, timeout) |
| 1050 | |
| 1051 | async def copy_records_to_table(self, table_name, *, records, |
| 1052 | columns=None, schema_name=None, |
| 1053 | timeout=None, where=None): |
| 1054 | """Copy a list of records to the specified table using binary COPY. |
| 1055 | |
| 1056 | :param str table_name: |
| 1057 | The name of the table to copy data to. |
| 1058 | |
| 1059 | :param records: |
| 1060 | An iterable returning row tuples to copy into the table. |
| 1061 | :term:`Asynchronous iterables <python:asynchronous iterable>` |
| 1062 | are also supported. |
| 1063 | |
| 1064 | :param list columns: |
| 1065 | An optional list of column names to copy. |
| 1066 | |
| 1067 | :param str schema_name: |
| 1068 | An optional schema name to qualify the table. |
| 1069 | |
| 1070 | :param str where: |
| 1071 | An optional SQL expression used to filter rows when copying. |
| 1072 | |
| 1073 | .. note:: |
| 1074 | |
| 1075 | Usage of this parameter requires support for the |
| 1076 | ``COPY FROM ... WHERE`` syntax, introduced in |
| 1077 | PostgreSQL version 12. |
| 1078 | |
| 1079 | |
| 1080 | :param float timeout: |
| 1081 | Optional timeout value in seconds. |
| 1082 | |
| 1083 | :return: The status string of the COPY command. |
| 1084 | |
| 1085 | Example: |
| 1086 | |
| 1087 | .. code-block:: pycon |
| 1088 | |
| 1089 | >>> import asyncpg |
| 1090 | >>> import asyncio |
| 1091 | >>> async def run(): |
| 1092 | ... con = await asyncpg.connect(user='postgres') |
| 1093 | ... result = await con.copy_records_to_table( |
| 1094 | ... 'mytable', records=[ |
| 1095 | ... (1, 'foo', 'bar'), |
| 1096 | ... (2, 'ham', 'spam')]) |
| 1097 | ... print(result) |
| 1098 | ... |
| 1099 | >>> asyncio.run(run()) |
| 1100 | 'COPY 2' |
| 1101 | |
| 1102 | Asynchronous record iterables are also supported: |
| 1103 | |
| 1104 | .. code-block:: pycon |
| 1105 | |
| 1106 | >>> import asyncpg |
| 1107 | >>> import asyncio |
| 1108 | >>> async def run(): |
nothing calls this directly
no test coverage detected