xo / usql

Universal command-line interface for SQL databases
MIT License
8.81k stars 346 forks source link

#321: postgres and pgx support schema name in \copy #460

Closed murfffi closed 2 months ago

murfffi commented 2 months ago

Closes #321

Adds support postgres and pgx support schema name in table destination in \copy. TestCopy in drivers_test is extended with cases with schema names. go test -v -tags pgx . -dbs=pgsql,pgx -test.run=TestCopy after the fix. The new test cases failed without the fix.

Even the existing test case for pgx failed for me with this output:

$ go test -v -tags pgx . -dbs=pgsql,pgx -test.run=TestCopy
=== RUN   TestCopy
2024/04/28 20:10:49 Could not copy: ERROR: COPY from stdin failed: unable to encode (*interface {})(0xc0002b4120) into binary format for int4 (OID 23): cannot find encode plan (SQLSTATE 57014)
FAIL    github.com/xo/usql/drivers      0.048s
FAIL

I added code to dereference the pointers populated by Scan before passing them to pgx.Copy to resolve that issue.