Re: psql and regex not like

From: Renan Alves Fonseca <renanfonseca(at)gmail(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-13 21:48:05
Message-ID: CAN_p2QiMGyJBYyuGjfvofO81p=wJvbYp-x=LgNEX=ueHx_F=nw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Another dirty hack:

MAGIC=\! psql -Xc "select datname from pg_database WHERE datname $MAGIC~
'template|postgres' ORDER BY datname;"

Em qui., 6 de mar. de 2025 às 10:38, Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
escreveu:

> 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?
>
> (Yes, I could create a view and then query the view, but I'm going to be
> running this remotely against dozens of servers, so I don't want to have to
> create dozens of views, then need to recreate them every time I want to
> change the query.)
>
> --
> Death to <Redacted>, and butter sauce.
> Don't boil me, I'm still alive.
> <Redacted> lobster!
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hans Schou 2025-03-13 23:09:16 Re: psql and regex not like
Previous Message Laurenz Albe 2025-03-13 19:34:01 Re: Query optimization