Skip to content

Commit 7bd7542

Browse files
committed
COPY with parameter is not supported
1 parent e0da87b commit 7bd7542

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/copy.jl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,12 @@ function execute(
119119
)
120120
level = throw_error ? error : warn
121121
if parameters !== nothing
122-
string_params = string_parameters(parameters)
123-
pointer_params = parameter_pointers(string_params)
122+
# https://postgrespro.com/list/thread-id/1893680
123+
throw(ArgumentError("COPY can't take any parameter"))
124124
end
125125

126126
copy_end_result = lock(jl_conn) do
127-
if parameters === nothing
128-
result = _execute(jl_conn.conn, copy.query)
129-
else
130-
result = _execute(jl_conn.conn, copy.query, pointer_params)
131-
end
127+
result = _execute(jl_conn.conn, copy.query)
132128
result_status = libpq_c.PQresultStatus(result)
133129

134130
if result_status != libpq_c.PGRES_COPY_OUT
@@ -154,8 +150,8 @@ function execute(
154150
seekstart(io) # rewind iobuffer so future user read will begin from start
155151
if -2 == status_code
156152
level(LOGGER, Errors.JLResultError(
157-
"PQgetCopyData error: $(error_message(jl_conn))"
158-
))
153+
"PQgetCopyData error: $(error_message(jl_conn))"
154+
))
159155
end
160156

161157
libpq_c.PQgetResult(jl_conn.conn)

test/runtests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ end
505505
@testset "Wrong COPY TO" begin
506506
conn = LibPQ.Connection("dbname=postgres user=$DATABASE_USER")
507507

508-
# test CopyOut!
508+
# test CopyOut! with an error
509509
databuf = IOBuffer()
510510
copyout = LibPQ.CopyOut!(databuf, "SELECT libpqjl_test;")
511511

@@ -517,6 +517,10 @@ end
517517
@test occursin("ERROR", err_msg)
518518
close(result)
519519

520+
# parameters are not supported
521+
copyout = LibPQ.CopyOut!(databuf, "COPY (SELECT * FROM libpqjl_test WHERE no_nulls = \$1) TO STDOUT (FORMAT CSV, HEADER');")
522+
@test_throws ArgumentError execute(conn, copyout, ['z'])
523+
520524
close(conn)
521525
end
522526
end

0 commit comments

Comments
 (0)