skip to Main Content
[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

Answers


  1. Chosen as BEST ANSWER
    su postgres -c "cd ~; psql -c 'SELECT * FROM pg_catalog.pg_user WHERE usename LIKE ''name'';'"
    

  2. /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%'"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search