Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tq9Uy-000FUm-4C for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 11:34:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tq9Uv-008FaN-Rl for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 11:34:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tq9Uv-008FaF-Gg for pgsql-general@lists.postgresql.org; Thu, 06 Mar 2025 11:34:41 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tq9Ut-001Hvo-2V for pgsql-general@postgresql.org; Thu, 06 Mar 2025 11:34:40 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-2bcceee7b40so424962fac.3 for ; Thu, 06 Mar 2025 03:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741260879; x=1741865679; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=RYP+tQErKPBx0GWhfN/z1cAHqLF/bqFjI82nBQRBPhk=; b=d8L+YyqKorMoYc8QfzEGQTXVvlqqHR/lTeRkE2ECJ7Vnrl85dn8Eg3uB8IC0P5fV6Y bP6tOU44LJgtD+z8yReqUXd6ubpKOnbzovvMN7fIJYM7x3tYE7vv3kMixseMWZR72fTu EUoTNDlukUIQ8dsiwxOPrtpvXOC/TQhJNHC9Lv3O5I6ElInQIL4VS0bUa9YUIkRszVV9 4PcXiDLbKrHZAX0JcCPbvePQhHWfR1Nl2enQOwdiX/6IHc2D6V2Ws9pOt7EPjcEBd/bA dbg9+aJ6sTIyWEqsd23d1D8qZGPeL2TRHVAtoFjMWad2w/jAWTVykFlyymWyICQURzXj cW9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741260879; x=1741865679; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RYP+tQErKPBx0GWhfN/z1cAHqLF/bqFjI82nBQRBPhk=; b=OrrKv4kJpsWgcDU2ldN0g0mwC+2+wQgps6ebuN6sdnF7+e0+romO4TEivmRssI6Vsw +xcN5eSt2iuVOt7d7oDuJ79kuiakNYc33xVVWoTcth/oI7bk93ubmy0VblJQetKopGiU BVgoJPkbSCbmiSfUcmYP8HtG9dkFhA9b0V/WeQsKifqi3MWEN4aAnMmtoHspvZKmL4Mk Z2Tgi1jE6a/GALrSXhYksFzXU7r9WCobjja4ba0MgjNkHrk9jpVP2dMHlNlticUNP0pG QcMUzO3MUCV6ORFSnMKO4tOi8L8N1dBXBGQZcSKsXJHEoGWumdTcsYXvyR0hAGnyidTM IUZA== X-Gm-Message-State: AOJu0YyBtVTxxDMJh05xJRMYniawXGDZ/sz61WOEinRVLXTMZJihxp81 ARGbhdyFOprEAjuFW+1sdgOFjW97BsN+O046oWuBrf4otCBvjAMM/Qx6UNPlY86yxAPMrSYSQhP 20j6S59avL9PiRXIcI1dSLTR9avkIAg== X-Gm-Gg: ASbGnct8UQ12ktxddCrQd+BQyx/+WodPcVMpAUuOSUhiqXQWvBe6dYLevPtpCxAkb6r qPcXmi2vfDFGny4dwYG5xQibBVov0A8bGcpcWMhbdfIcNL3ZgJ8WLvq4GsrSTTOOj/d68szcpkN vQg9hhAELLZjv6PN3aMlozSGDnmYyhs2iVhV+NCMYbsMCg0DGuKkpBBF+7vW1f X-Google-Smtp-Source: AGHT+IE4vonRnrVJXqPCF+YLwdmjyGsnZI9V4+A58frN0bYS8jPD5s5d6I5HFcw+/dbInow0BTg//iVga2utlpDCKMM= X-Received: by 2002:a05:6871:a9c3:b0:2bc:66cc:1507 with SMTP id 586e51a60fabf-2c21c920292mr3305884fac.12.1741260878988; Thu, 06 Mar 2025 03:34:38 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Thu, 6 Mar 2025 06:34:28 -0500 X-Gm-Features: AQ5f1Jom_fF1C7aBfTGFpXbY7uBdjoPCQmV60_x6qQtgu0DwV1swokqMmfOGZS8 Message-ID: Subject: Re: psql and regex not like To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000002753d9062faae42e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002753d9062faae42e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 6, 2025 at 6:11=E2=80=AFAM hubert depesz lubaczewski wrote: > 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;" > I've used WHERE NOT ()" before. Should have thought of it here. Thanks. --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --0000000000002753d9062faae42e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Mar 6, 2025 at 6:11=E2=80=AFAM hu= bert depesz lubaczewski <depesz@dep= esz.com> wrote:
On Thu, Mar 06, 2025 at= 04:37:56AM -0500, Ron Johnson wrote:
> This statement runs great from the psql prompt.=C2=A0 Does exactly wha= t I want.
> select datname from pg_database WHERE datname !~ 'template|postgre= s' ORDER
> BY datname;
> But it doesn't work so well from the bash prompt.=C2=A0 Not escapi= ng the "!"
> generates a bunch of garbage, while escaping throws an sql syntax erro= r.

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 ~ 'tem= plate|postgres' ORDER BY datname;"

=
I've used WHERE NOT ()" before.=C2=A0 Should have thought of = it here.

Thanks.

--
Death to <Redacted>, and butter sauce.=
Don't boil me, I'm still alive.
<Redacted> = lobster!
--0000000000002753d9062faae42e--