Re: psql and regex not like

From: François Lafont <francois(dot)lafont(dot)1978(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql and regex not like
Date: 2025-03-06 10:45:49
Message-ID: 162b5950-1918-4001-87d3-27bb01586538@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2025-03-06 11:11:10 Re: psql and regex not like
Previous Message Dominique Devienne 2025-03-06 10:41:42 Re: psql and regex not like