public inbox for [email protected]
help / color / mirror / Atom feedFrom: François Lafont <[email protected]>
To: pgsql-general <[email protected]>
Subject: Re: psql and regex not like
Date: Thu, 6 Mar 2025 11:45:49 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CANzqJaCmmqNjSNitxWPekwM7mQesZCfAdXjOprKao8Ted35E-w@mail.gmail.com>
References: <CANzqJaCmmqNjSNitxWPekwM7mQesZCfAdXjOprKao8Ted35E-w@mail.gmail.com>
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
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: psql and regex not like
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox