question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Able to pipe query into stdin and get csv on stdout

See original GitHub issue

We use commandline tools to transfer data from postgresql, mysql and sqlserver to (in our case) a postgresql server.

The basic idea is like this (in this case we get data from mysql and import it in postgresql:

# schema.table was created to have the same layout as whatever is getting out of the csv
echo "SELECT ... FROM ...; " | /bin/bash -o pipefail -c "\
MYSQL_PWD=password mysql --user=projecta --host=x.x.x.x --port=xxxx   --skip-column-names | \
PGOPTIONS='--client-min-messages=warning' PGTZ=Europe/Berlin \
psql --username=xxx --host=hostname --no-psqlrc --set ON_ERROR_STOP=on database --echo-queries \
--command=\"COPY schema.table FROM STDIN WITH NULL AS 'NULL'\"";

[we also run all our ETL via sending queries to stdin of a psql call, but to support that in mssql-cli would also mean “import csv on stdin” support to actually get the data into sql server]

For sqlserver, we currently use sqsh but supports at least the “SQL Script in, csv out” workflow. As sqsh is unmaintained (and buggy in versions available in ubuntu/debian), we would like to replace this by whatever finally supports at least exporting csv on stdout.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:16
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
sbrandtbcommented, Jan 8, 2018

This could be split into

  • query from stdin (or file)
  • csv stdout

The first one is keeping me from replacing microsoft’s crappy sqlcmd client with mssql-cli

4reactions
MrMeemuscommented, Jan 28, 2019

@JamesCass, thanks for the comment! Yes we are planning on updating the tool so we can target those specific scenarios regarding automation and scripting. A rough ETA would be some time March - April time frame.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL import from stdin - Stack Overflow
You can't pipe the csv out direct to mysql. You have to do extra work to make the result be valid sql. Or,...
Read more >
AWS Command line: S3 content from stdin or to stdout - Loige
This article presents a quick tip that will help you deal with the content of files in S3 through the AWS command line...
Read more >
Export to CSV from PSQL using the copy command
This article discusses how to export data from psql to a csv file using the copy commands.
Read more >
Documentation: 15: COPY - PostgreSQL
In COPY FROM , the input is read from standard output of the command, and in ... This option is allowed only in...
Read more >
The CSV output format in psql
Exporting query results in CSV has been possible for a long time(since version 8.0), either withCOPY (SELECT ...) TO STDOUT CSV as an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found