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 1tq8PG-00HYcw-1E for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 10:24:46 +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 1tq8PE-006IOZ-Cl for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 10:24:44 +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 1tq8PE-006IOR-00 for pgsql-general@lists.postgresql.org; Thu, 06 Mar 2025 10:24:44 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tq8PC-001HKI-0a for pgsql-general@postgresql.org; Thu, 06 Mar 2025 10:24:43 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7272f9d216dso265149a34.3 for ; Thu, 06 Mar 2025 02:24:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741256681; x=1741861481; 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=AmD7vJE/dKgpdP1z6WK8c1tPpGB6zBLZyz3HMQImIFg=; b=GAavursKFCf7U16lIk4r+08g/+tUkgJl/8IgSMrcz2CXimpv/xqw1dyZlqfMJdI3Tu EB8aVnysHUDpTs45ezeaTQYyBuRp4UVdWYJLiYrYRHdIPdg9am3IaK93aVlB8HR75tAp 0Tz7sBsM9l2+qzG0znKlV4OcIgUDAMe1d4jFfT/U6fEi53Utfg+07GUTknT2j0MWqKN/ zAg8wfZ+OoYU89tRzGBrD5JAjHkK4hwqZ2zwZYY2xeGcziFUfMUEj57lDbWxbn1BgmE8 TssoKlR0QVWsZA7VzX3JfBPCt9j+0lJ/7ToGf8vg7+NRSHqPUbXx5eIJG/KscnWchwjW qj3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741256681; x=1741861481; 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=AmD7vJE/dKgpdP1z6WK8c1tPpGB6zBLZyz3HMQImIFg=; b=rBUkmxgo1Zw+SHIwK6ovyUnB3ZIYAECUfnC/N+6uTnG3k8lIUdaXPqJmJ9BXq8297G FY35l8J4fMqZKCPHtpyUy/Hgtr3pPtKkmxQ0XU30Us4BHZHBG/NPiMljLb7WgWgNSKns uuSsS7Uwg8uZJVxqo7G3YyXKHS262gpTEQPLxd4WwGkL7DApMTFtGq0EuFqz3XuczTSo rieD8czWLM3VfpdM5sOhrIYikuExLuA3tJTsnw2HIZp9yZfacb3f/NnkAFRulmd5CkvA +s5va2OrVDmH4eWjvR5Jfa1ZXwyQzu8RcqxG0Bgz92lk0SEDsyNBPAfRo9tyuMi1EBYG 8c4A== X-Gm-Message-State: AOJu0YzYHwViGSGKlXd+pDAdJAuYih5gsosE26E8lAGgP8R5mCNeugFo UISboRaZacDlvEjRtIa8YlVI/3ftTwCWAVa3ypq2oHsduPTzVCv9BMN9aIfZPVcoqcN5UqnUHph 8DEFG5ktRR2BLWxjb/ByoL9AMCFr1aw== X-Gm-Gg: ASbGnctVlHJBSEnUKYNf+5mCjwXe7jMAt3dHY49WjfsI2gWKzkB6u/SwHY1UVVBOx3t 8drGpJQfJs377m01JaYEv+3o3bW78hWVTgnf5NfOhaP67bAmO9m9ybRN32Ikd6RQTMQv4K7ryXN +YvuOTWfyugt+X4ywCDMQC32dFVqc= X-Google-Smtp-Source: AGHT+IEuCcEU+AZimsvRh0eJhwVpUIhjelzk6Wubhkzyx8bVh/Tb7hUix7wTTmvRwJxNH+HM0NdJO1w1LvukFTMWg3Q= X-Received: by 2002:a05:6830:4108:b0:71e:946:80c4 with SMTP id 46e09a7af769-72a1fbfbb12mr3185084a34.12.1741256681435; Thu, 06 Mar 2025 02:24:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Thu, 6 Mar 2025 05:24:29 -0500 X-Gm-Features: AQ5f1JoOBoZMmyXpVfskZCSEF7ZFE8HWduIOwPgDWDLv-L_9at1ZhrReWl55yXI Message-ID: Subject: Re: psql and regex not like To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000f5bd88062fa9e9a3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f5bd88062fa9e9a3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 6, 2025 at 4:59=E2=80=AFAM Dominique Devienne wrote: > On Thu, Mar 6, 2025 at 10:38=E2=80=AFAM 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? > > > > (Yes, I could create a view and then query the view, but I'm going to b= e > 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.) > > No answer to your question, but I'd argue it's moot, because it's not > the right query in the first place :) > It should be instead, IMHO, the one below, which should be OK in BASH > syntax-wise. --DD > > select datname from pg_database WHERE datistemplate =3D false and > datname <> 'postgres' order by 1 > I already do that. This is part of a long chain of commands so I'm trying to minimize the length of commands. Anyway, it would be good to know the answer for any future queries that need multiple exclusions. --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000f5bd88062fa9e9a3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Mar 6, 2025 at 4:59=E2=80=AFAM Do= minique Devienne <ddevienne@gmail= .com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Mar 6, 2025 at 10:= 38=E2=80=AFAM Ron Johnson <ronljohnsonjr@gmail.com> 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 error.
>
> psql -Xc "select datname from pg_database WHERE datname \!~ '= template|postgres' ORDER BY datname;"
> ERROR:=C2=A0 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.)

No answer to your question, but I'd argue it's moot, because it'= ;s not
the right query in the first place :)
It should be instead, IMHO, the one below, which should be OK in BASH
syntax-wise. --DD

select datname from pg_database WHERE datistemplate =3D false and
datname <> 'postgres' order by 1

I already do that.=C2= =A0 This is part of a long chain of commands so I'm trying to minimize = the length of commands.

Anyway, it would be good t= o know the answer for any future queries that need multiple exclusions.

--
Death to <Redacte= d>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
--000000000000f5bd88062fa9e9a3--