Re: psql and regex not like

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql and regex not like
Date: 2025-03-06 11:11:10
Message-ID: Z8mCzjdL87tEK4xT@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Mar 06, 2025 at 04:37:56AM -0500, 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.

The problem is that ! is magical in bash.

The solution is to not use it. Instead you can easily do:

psql -Xc "select datname from pg_database WHERE not datname ~ 'template|postgres' ORDER BY datname;"

Best regards,

depesz

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2025-03-06 11:34:28 Re: psql and regex not like
Previous Message François Lafont 2025-03-06 10:45:49 Re: psql and regex not like