Skip to content

Files

Latest commit

 Cannot retrieve latest commit at this time.

History

History
44 lines (30 loc) · 1.75 KB

cli_example.md

File metadata and controls

44 lines (30 loc) · 1.75 KB

CLI example

adbcduck-go is compatible with usql - the universal SQL CLI - a fully featured, single-binary, CLI for over 50 databases. usqlgen is used add adbcduck-go to usql.

To install usql with adbcduck driver, run:

# install usql with added adbcduck-go driver that automatically downloads latest DuckDB
go run github.com/sclgo/usqlgen@latest install -i github.com/sclgo/adbcduck-go/quickstart

Review the usqlgen documentation for more options

For example, let's use DuckDB to read Parquet files on S3 and copy the results into Microsoft SQL Server (MSSQL):

First, we prepare the MSSQL and DuckDB schemas. In the example, we use MSSQL running on localhost with sa password Foobar12 . The Parquet data in the example is the open Daylight Earth dataset from OpenStreetMap.

usql adbcduck:s3schema.db -c "CREATE OR REPLACE VIEW earth AS SELECT * FROM read_parquet('s3://daylight-openstreetmap/earth/release=v1.58/*/*', hive_partitioning = true)"
usql ms://sa:Foobar12@localhost:1433 -c 'CREATE TABLE earth_copy("class" varchar(200), "subclass" varchar(200), names text)'

Then start usql and copy the data

usql
# the following commands go on the usql interactive prompt:

# copy data
\copy adbcduck:s3schema.db ms://sa:Foobar12@localhost:1433 "select class, subclass, names from earth where theme = 'landuse' limit 20" earth_copy

# review some copied data
\connect ms://sa:Foobar12@localhost:1433
select count(1), subclass from earth_copy group by subclass;

You should see something like:

install output

copy data output