noborus / trdsql

CLI tool that can execute SQL queries on CSV, LTSV, JSON, YAML and TBLN. Can output to various formats.
https://noborus.github.io/trdsql/
MIT License
1.96k stars 73 forks source link

-driver postgres returns SSL error #158

Closed rdsedmundo closed 3 years ago

rdsedmundo commented 3 years ago
trdsql -driver postgres -ih -ocsv "SELECT * FROM file.csv WHERE lpad(a, 9, '0') != replace(b, '-', '') LIMIT 10"
2021/06/02 13:03:49 begin: pq: SSL is not enabled on the server

I'm not sure what I'm supposed to do here. I just wanted to use the lpad function thus I added the -driver option. Setting up SSL on a localhost instance seems overkill.

noborus commented 3 years ago

You need dsn to connect to the database.

trdsql -driver postgres -dsn 'host=localhost port=5432 dbname=postgres' -ih -ocsv "SELECT * FROM file.csv WHERE lpad(a, 9, '0') != replace(b, '-', '') LIMIT 10"

UNIX Domain Socket

trdsql -driver postgres -dsn 'host=/var/run/postgresql/ port=5432 dbname=postgres' -ih -ocsv "SELECT * FROM file.csv WHERE lpad(a, 9, '0') != replace(b, '-', '') LIMIT 10"

See https://pkg.go.dev/github.com/lib/pq#hdr-Connection_String_Parameters for more information. You can also disable sslmode in dsn(sslmode=disable).

rdsedmundo commented 3 years ago

Thanks, I ended up using PGSSLMODE=disable env var to control it so I can just pass -driver postgres.