I am trying to execute a non-interactive postgres command.
PGPASSWORD=$PGPASS psql -h 127.0.0.1 -U postgresql -d $PGDB --command "select count(*) from services"
Which has been giving me this response.
psql: warning: extra command-line argument "from" ignored
psql: warning: extra command-line argument "services;" ignored
psql: warning: extra command-line argument "mydbname" ignored
psql: FATAL: database "count(*)" does not exist
I've read that this could be because the terminal / bash is trying to break up each argument to --command
/ -c
as it's own argument.
I've also tried this:
PSQLARGS=(-h 127.0.0.1 -U postgresql -c )
PSQLARGS+=("select count(*) from services;")
PSQLARGS+=(${PGDB})
PGPASSWORD=$PGPASS psql "${PSQLARGS[@]}"
Some way of forcing the terminal to know it's one argument, this also didn't work.