passing sql via command line a la '-c' for psql?
Description
I don't see a 'sql via the command ilne switch' option which is surprising. Just want to make sure I'm not missing anything. I've tried just appending sql to the end of a database connection and also using '-c', neither of which work.
Your environment
MacOS
- [x] Please provide your OS and version information. 10.15.7
- [x] Please provide your CLI version. 3.1.0
- [ ] What is the output of
pip freezecommand.
pgcli is designed for interactive use. We're not specifically against implementing non-interactive use cases, they just have not been a priority. We welcome any PRs.
@jonassteinberg1 I'd recommend changing to use all the PG env vars for host/user/password then psql postgres < $HOME/sql/show_full_processlist.sql I've used this style on lots of different db platforms like postgres, mysql and others. pgcli is way better at being a SQL IDE interactively. Just the syntax highlighting is worth it's weight in gold. Great work to the devs on this one. Love it.
You can kind of do it in a hacky way if you really want to:
# set your env vars then
PGPASSWORD=$SRC_DB_PASS pgcli \
--less-chatty \
-h $SRC_DB_HOST \
-u $SRC_DB_USER \
$SRC_DB_NAME <<STDIN
SELECT * \
FROM information_schema.tables \
WHERE table_schema = '$SRC_DB_SCHEMA';
STDIN
But to @j-bennet 's point, psql is likely easier to install and use like so:
PGPASSWORD=$SRC_DB_PASS psql \
--csv \
-h $SRC_DB_HOST \
-U $SRC_DB_USER \
$SRC_DB_NAME <<STDIN
SELECT * \
FROM information_schema.tables
WHERE table_schema = '$SRC_DB_SCHEMA';
STDIN