Skip to content

Commit b335cd5

Browse files
committed
Add docs for CopyOut!
1 parent 137a769 commit b335cd5

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
@@ -75,9 +75,9 @@ LibPQ.load!(
7575
execute(conn, "COMMIT;")
7676
```
7777

78-
### `COPY`
78+
### `COPY FROM`
7979

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

8383
```julia
@@ -99,3 +99,23 @@ execute(conn, copyin)
9999

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

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)