https://github.com/frederikhs/sql2csv-cmd
cli application for extracting data as csv from a PostgreSQL database using sql
https://github.com/frederikhs/sql2csv-cmd
csv go sql
Last synced: about 1 month ago
JSON representation
cli application for extracting data as csv from a PostgreSQL database using sql
- Host: GitHub
- URL: https://github.com/frederikhs/sql2csv-cmd
- Owner: frederikhs
- License: gpl-3.0
- Created: 2023-03-01T14:46:09.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-01T21:56:31.000Z (about 3 years ago)
- Last Synced: 2024-06-21T03:13:35.104Z (almost 2 years ago)
- Topics: csv, go, sql
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
# sql2csv-cmd
[](https://godoc.org/github.com/frederikhs/sql2csv-cmd)
[](https://goreportcard.com/report/github.com/frederikhs/sql2csv-cmd)
[](https://github.com/frederikhs/sql2csv-cmd/actions/workflows/test.yml)
[](https://github.com/frederikhs/sql2csv-cmd/releases/latest)
[](LICENSE)
*cli application for extracting data as csv from a PostgreSQL database using sql*
## Usage
```text
Usage of sql2csv-cmd:
-c string
connection string for the database: postgres://user:pass@host:port/dbname
-d string
hostname for database as defined in .pgpass
-f string
file containing query to run eg. query.sql
-o string
output filename eg. result.csv
-q string
query to run
-t int
query timeout in seconds
-v verbose mode
```
## Example
```shell
sql2csv-cmd -d db.example.com -q "SELECT * FROM public.users" -o users.csv
```
```shell
sql2csv-cmd -d db.example.com -f query.sql -o query.csv
```
## Installation
### Linux amd64
```bash
# install
curl -L https://github.com/frederikhs/sql2csv-cmd/releases/latest/download/sql2csv-cmd_Linux_x86_64.tar.gz -o sql2csv-cmd.tar.gz
tar -xvf sql2csv-cmd.tar.gz
sudo mv sql2csv-cmd /usr/local/bin/sql2csv-cmd
# clean up
rm sql2csv-cmd.tar.gz
```
## .pgpass
sql2csv-cmd uses the `.pgpass` file that resides in the `$HOME` directory of the user running the program.
---
Example of a connection configuration in the `.pgpass` file
```
::::
```