0
[servername]# su postgres -c 'cd ~; psql -c "SELECT * FROM pg_catalog.pg_user WHERE usename LIKE name;"'
ERROR:  column "name" does not exist
LINE 1: SELECT * FROM pg_catalog.pg_user WHERE usename LIKE name;
                                                            ^

Tried vary ways but no one of them return the correct response. May be there's a prettier way to do command-line queries?

2 Answers2

0
/usr/local/pgsql15/bin/psql  -c "SELECT * FROM pg_catalog.pg_user WHERE usename like 'admin'"

make it two line.

/usr/local/pgsql15/bin/psql test15  -c  \
"SELECT * FROM pg_catalog.pg_user WHERE usename like 'admin'"

or

/usr/local/pgsql15/bin/psql test15  <<<"SELECT * FROM pg_catalog.pg_user WHERE usename like 'admin'"

or

echo "SELECT * FROM pg_catalog.pg_user WHERE usename like 'admin'" | /usr/local/pgsql15/bin/psql test15

percent sign still works.

/usr/local/pgsql15/bin/psql test15  -c  \
"SELECT * FROM pg_catalog.pg_user WHERE usename like '%admi%'"
jian
  • 4,119
  • 1
  • 17
  • 32
0
su postgres -c "cd ~; psql -c 'SELECT * FROM pg_catalog.pg_user WHERE usename LIKE '\'name\'';'"
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Nov 20 '22 at 09:30