Skip to content

Commit b3370b6

Browse files
committed
Add docs for CopyOut!
1 parent 34616d9 commit b3370b6

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

docs/src/index.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ LibPQ.load!(
7171
execute(conn, "COMMIT;")
7272
```
7373

74-
### `COPY`
74+
### `COPY FROM`
7575

76-
An alternative to repeated `INSERT` queries is the PostgreSQL `COPY` query.
76+
An alternative to repeated `INSERT` queries is the PostgreSQL `COPY FROM` query.
7777
`LibPQ.CopyIn` makes it easier to stream data to the server using a `COPY FROM STDIN` query.
7878

7979
```julia
@@ -95,3 +95,23 @@ execute(conn, copyin)
9595

9696
close(conn)
9797
```
98+
99+
### `COPY TO`
100+
101+
An alternative to selection for large datasets in `SELECT` queries is the PostgreSQL `COPY TO` query.
102+
`LibPQ.CopyOut!` makes it easier to stream data out of the server using a `COPY TO STDIN` query.
103+
104+
```julia
105+
using LibPQ, CSV, DataFrames
106+
107+
conn = LibPQ.Connection("dbname=postgres user=$DATABASE_USER")
108+
109+
databuf = IOBuffer()
110+
copyout = LibPQ.CopyOut!(databuf, "COPY (SELECT * FROM libpqjl_test) TO STDOUT (FORMAT CSV, HEADER);")
111+
112+
execute(conn, copyout)
113+
114+
df = DataFrame(CSV.File(databuf))
115+
116+
close(conn)
117+
```

docs/src/pages/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ LibPQ.load!
4343
```@docs
4444
LibPQ.CopyIn
4545
execute(::LibPQ.Connection, ::LibPQ.CopyIn)
46+
LibPQ.CopyOut!
47+
execute(::LibPQ.Connection, ::LibPQ.CopyOut!)
4648
```
4749

4850
### Asynchronous

0 commit comments

Comments
 (0)