@@ -378,11 +378,25 @@ async def copy_from_table(self, table_name, *, output,
378
378
379
379
:return: The status string of the COPY command.
380
380
381
- .. versionadded:: 0.11.0
381
+ Example:
382
+
383
+ .. code-block:: pycon
384
+
385
+ >>> import asyncpg
386
+ >>> import asyncio
387
+ >>> async def run():
388
+ ... con = await asyncpg.connect(user='postgres')
389
+ ... result = await con.copy_from_table(
390
+ ... 'mytable', columns=('foo', 'bar'),
391
+ ... output='file.csv', format='csv')
392
+ ... print(result)
393
+ >>> asyncio.get_event_loop().run_until_complete(run())
394
+ 'COPY 100'
382
395
383
396
.. _`COPY statement documentation`: https://www.postgresql.org/docs/\
384
397
current/static/sql-copy.html
385
398
399
+ .. versionadded:: 0.11.0
386
400
"""
387
401
tabname = utils ._quote_ident (table_name )
388
402
if schema_name :
@@ -415,7 +429,7 @@ async def copy_from_query(self, query, *args, output,
415
429
:param str query:
416
430
The query to copy the results of.
417
431
418
- :param *args:
432
+ :param \ *args:
419
433
Query arguments.
420
434
421
435
:param output:
@@ -432,11 +446,25 @@ async def copy_from_query(self, query, *args, output,
432
446
433
447
:return: The status string of the COPY command.
434
448
435
- .. versionadded:: 0.11.0
449
+ Example:
450
+
451
+ .. code-block:: pycon
452
+
453
+ >>> import asyncpg
454
+ >>> import asyncio
455
+ >>> async def run():
456
+ ... con = await asyncpg.connect(user='postgres')
457
+ ... result = await con.copy_from_query(
458
+ ... 'SELECT foo, bar FROM mytable WHERE foo > $1', 10,
459
+ ... output='file.csv', format='csv')
460
+ ... print(result)
461
+ >>> asyncio.get_event_loop().run_until_complete(run())
462
+ 'COPY 10'
436
463
437
464
.. _`COPY statement documentation`: https://www.postgresql.org/docs/\
438
465
current/static/sql-copy.html
439
466
467
+ .. versionadded:: 0.11.0
440
468
"""
441
469
opts = self ._format_copy_opts (
442
470
format = format , oids = oids , delimiter = delimiter ,
@@ -469,7 +497,7 @@ async def copy_to_table(self, table_name, *, source,
469
497
or a :term:`file-like object <python:file-like object>`, or
470
498
an :term:`asynchronous iterable <python:asynchronous iterable>`
471
499
that returns ``bytes``, or an object supporting the
472
- :term :`buffer protocol <python:buffer protocol >`.
500
+ :ref :`buffer protocol <python:bufferobjects >`.
473
501
474
502
:param list columns:
475
503
An optional list of column names to copy.
@@ -485,11 +513,24 @@ async def copy_to_table(self, table_name, *, source,
485
513
486
514
:return: The status string of the COPY command.
487
515
488
- .. versionadded:: 0.11.0
516
+ Example:
517
+
518
+ .. code-block:: pycon
519
+
520
+ >>> import asyncpg
521
+ >>> import asyncio
522
+ >>> async def run():
523
+ ... con = await asyncpg.connect(user='postgres')
524
+ ... result = await con.copy_to_table(
525
+ ... 'mytable', source='datafile.tbl')
526
+ .... print(result)
527
+ >>> asyncio.get_event_loop().run_until_complete(run())
528
+ 'COPY 140000'
489
529
490
530
.. _`COPY statement documentation`: https://www.postgresql.org/docs/\
491
531
current/static/sql-copy.html
492
532
533
+ .. versionadded:: 0.11.0
493
534
"""
494
535
tabname = utils ._quote_ident (table_name )
495
536
if schema_name :
@@ -535,6 +576,22 @@ async def copy_records_to_table(self, table_name, *, records,
535
576
536
577
:return: The status string of the COPY command.
537
578
579
+ Example:
580
+
581
+ .. code-block:: pycon
582
+
583
+ >>> import asyncpg
584
+ >>> import asyncio
585
+ >>> async def run():
586
+ ... con = await asyncpg.connect(user='postgres')
587
+ ... result = await con.copy_records_to_table(
588
+ ... 'mytable', records=[
589
+ ... (1, 'foo', 'bar'),
590
+ ... (2, 'ham', 'spam')])
591
+ .... print(result)
592
+ >>> asyncio.get_event_loop().run_until_complete(run())
593
+ 'COPY 2'
594
+
538
595
.. versionadded:: 0.11.0
539
596
"""
540
597
tabname = utils ._quote_ident (table_name )
0 commit comments