Last active
February 10, 2021 04:09
-
-
Save dantonnoriega/95cecececbdc4d84dd7c92e7f361de00 to your computer and use it in GitHub Desktop.
Useful functions for parsing postgres commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function psql_cmd() { | |
echo "$1" | psql -h $POSTGRES_HOST -U $POSTGRES_USERNAME -d $POSTGRES_DB -p $POSTGRES_PORT | |
} | |
# output data easy to ingest into R or python (includes header; can pass to `tee`) | |
function psql_psv() { | |
echo "$1" | psql -h $POSTGRES_HOST -U $POSTGRES_USERNAME -d $POSTGRES_DB -p $POSTGRES_PORT -A -F' | ' | grep -vE "\(\d+ row[s]\)" | |
} | |
function psql_csv() { | |
echo "$1" | psql -h $POSTGRES_HOST -U $POSTGRES_USERNAME -d $POSTGRES_DB -p $POSTGRES_PORT --csv | |
} | |
function psql_copy_to() { | |
echo "$1" | psql -h $POSTGRES_HOST -U $POSTGRES_USERNAME -d $POSTGRES_DB -p $POSTGRES_PORT -o $2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment