Skip to content

Instantly share code, notes, and snippets.

@sousk
Created April 22, 2019 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sousk/dfb60957c8d4da7c828916cd4a6cd104 to your computer and use it in GitHub Desktop.
Save sousk/dfb60957c8d4da7c828916cd4a6cd104 to your computer and use it in GitHub Desktop.
dump SQL select into CSV with gcolud spanner command
gcloud spanner databases execute-sql dbname --instance=instance-name --project=project-name --format=json --sql=(cat query.sql | ruby -e 'STDIN.select{|l| ! l.match /^[\s\t]*--/ }.each{|l| print l.chomp, " "}') | jq -r '.rows[] | map(.[0]) | map("\"" + . + "\"") | join(",")' > result.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment