Copy the results of a query to a file or file-like object. :param str query: The query to copy the results of. :param args: Query arguments. :param output: A :term:`path-like object `, or a :term:`fil
(self, query, *args, output,
timeout=None, format=None, oids=None,
delimiter=None, null=None, header=None,
quote=None, escape=None, force_quote=None,
encoding=None)
| 876 | return await self._copy_out(copy_stmt, output, timeout) |
| 877 | |
| 878 | async def copy_from_query(self, query, *args, output, |
| 879 | timeout=None, format=None, oids=None, |
| 880 | delimiter=None, null=None, header=None, |
| 881 | quote=None, escape=None, force_quote=None, |
| 882 | encoding=None): |
| 883 | """Copy the results of a query to a file or file-like object. |
| 884 | |
| 885 | :param str query: |
| 886 | The query to copy the results of. |
| 887 | |
| 888 | :param args: |
| 889 | Query arguments. |
| 890 | |
| 891 | :param output: |
| 892 | A :term:`path-like object <python:path-like object>`, |
| 893 | or a :term:`file-like object <python:file-like object>`, or |
| 894 | a :term:`coroutine function <python:coroutine function>` |
| 895 | that takes a ``bytes`` instance as a sole argument. |
| 896 | |
| 897 | :param float timeout: |
| 898 | Optional timeout value in seconds. |
| 899 | |
| 900 | The remaining keyword arguments are ``COPY`` statement options, |
| 901 | see `COPY statement documentation`_ for details. |
| 902 | |
| 903 | :return: The status string of the COPY command. |
| 904 | |
| 905 | Example: |
| 906 | |
| 907 | .. code-block:: pycon |
| 908 | |
| 909 | >>> import asyncpg |
| 910 | >>> import asyncio |
| 911 | >>> async def run(): |
| 912 | ... con = await asyncpg.connect(user='postgres') |
| 913 | ... result = await con.copy_from_query( |
| 914 | ... 'SELECT foo, bar FROM mytable WHERE foo > $1', 10, |
| 915 | ... output='file.csv', format='csv') |
| 916 | ... print(result) |
| 917 | ... |
| 918 | >>> asyncio.run(run()) |
| 919 | 'COPY 10' |
| 920 | |
| 921 | .. _`COPY statement documentation`: |
| 922 | https://www.postgresql.org/docs/current/static/sql-copy.html |
| 923 | |
| 924 | .. versionadded:: 0.11.0 |
| 925 | """ |
| 926 | opts = self._format_copy_opts( |
| 927 | format=format, oids=oids, delimiter=delimiter, |
| 928 | null=null, header=header, quote=quote, escape=escape, |
| 929 | force_quote=force_quote, encoding=encoding |
| 930 | ) |
| 931 | |
| 932 | if args: |
| 933 | query = await utils._mogrify(self, query, args) |
| 934 | |
| 935 | copy_stmt = 'COPY ({query}) TO STDOUT {opts}'.format( |
nothing calls this directly
no test coverage detected