Skip to content

Conversation

@ejiektpobehuk
Copy link

This PR addresses #495 and similar issues I've experienced.

\copy had no support for connection variables set with \cset or a configuration file.
It went straight to parsing the source and destination with dburl.Parse().

I've copied the Handler.Open() behaviour without any DRY.
Now it can handle connection variables.

@ejiektpobehuk
Copy link
Author

ejiektpobehuk commented Nov 25, 2025

I'd like to add a test to the test suite. My current version is file system dependant and I'm not sure if it's a good fit. On the other hand this test uses csvq and sqlite3 which are built-in and don't require external databases.

-- Create source data
\! mkdir -p /tmp/usql_test
\! echo "id,name,value" > /tmp/usql_test/source.csv
\! echo "1,Alice,100" >> /tmp/usql_test/source.csv
\! echo "2,Bob,200" >> /tmp/usql_test/source.csv
\! echo "3,Charlie,300" >> /tmp/usql_test/source.csv

-- Set up connection variables using \cset
\cset SOURCE csvq:///tmp/usql_test
\cset DEST sq:/tmp/usql_test/dest.db

-- Create destination table
\c DEST
CREATE TABLE test_table (
  id INTEGER PRIMARY KEY,
  name TEXT,
  value INTEGER
);

-- Test target
\copy SOURCE DEST 'SELECT * FROM `source.csv`' 'test_table'

-- Verify the data was copied
\c DEST
SELECT * FROM test_table;

-- Cleanup
\! rm -rf /tmp/usql_test

\quit

@ejiektpobehuk
Copy link
Author

Test results before the patch:

CREATE TABLE
error: invalid database scheme
(0 rows)

Test results after the patch:

CREATE TABLE
COPY 3
 id |  name   | value
----+---------+-------
  1 | Alice   |   100
  2 | Bob     |   200
  3 | Charlie |   300
(3 rows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants