Search Postgresql Archives

Re: psql and regex not like

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 3/6/25 10:37, Ron Johnson wrote:
This statement runs great from the psql prompt.  Does exactly what I want.
select datname from pg_database WHERE datname !~ 'template|postgres' ORDER BY datname;

But it doesn't work so well from the bash prompt.  Not escaping the "!" generates a bunch of garbage, while escaping throws an sql syntax error.

psql -Xc "select datname from pg_database WHERE datname \!~ 'template|postgres' ORDER BY datname;"
ERROR:  syntax error at or near "\"

What's the magic syntax?

Indeed it's a question about bash.

This works well for me:

    set +H
    psql -Xc "SELECT datname FROM pg_database WHERE datname !~ 'template|postgres' ORDER BY datname;"

~$ echo "!~"
-bash: !~: event not found

~$ set +H

~$ echo "!~"
!~

Bye.

--
François Lafont






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux