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 1tq80l-00HSIL-J4 for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 09:59:27 +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 1tq80k-005ZVQ-9v for pgsql-general@arkaria.postgresql.org; Thu, 06 Mar 2025 09:59:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tq80j-005ZVI-Uz for pgsql-general@lists.postgresql.org; Thu, 06 Mar 2025 09:59:25 +0000 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tq80g-001H8D-1w for pgsql-general@postgresql.org; Thu, 06 Mar 2025 09:59:25 +0000 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-60018359e1aso969030eaf.0 for ; Thu, 06 Mar 2025 01:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741255162; x=1741859962; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IIhr7rO4m/iG9nmE9m9wbA4+Elrbbc8m4hyxYcX5dpE=; b=WcLwh25c6Rvdz2OLmLB3IH47ytCkmws6ShQc+JFwI/C3S8o9v2l1f+SexDJQJPWI51 2SCJWl6gtk8CfXGklZ2/0n7K/bnuVtrKWRQs0Xn16K/vwgLFRnpUVOwIjRUo3mlglLGE B6whSBK6VHZ1g70GViv2vvFX0KRYWWCQ8/AvxLIAz2tBgNwIKPrck5zaY6LsleznZLfT Zn84VLE15Ca/rtv/joKV2B1KLaNZCdxrofhRJrsa0A1iEpB6R4D6auXosKYd0Ljzww9I us1OM8zXGYZW69WC9usClWH/BA9XaPs1qdPfXFwGUS7nLes/9ErhSTf+yEDhpLAFwDW1 AqSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741255162; x=1741859962; h=content-transfer-encoding:cc: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=IIhr7rO4m/iG9nmE9m9wbA4+Elrbbc8m4hyxYcX5dpE=; b=EYnRzxsYtKwwbQKe7kORRcQJKCmlq57fNVdo6Qz7rBMuMmNff+0GVh3q1+DbLCOR0n EU8UIr2Op3r3ywjR59tGrxFFrC/4ZEStXk3GIgJV+Y9CREdQQe6GS4THPOR4q9eLNv9u p10qJMQr5dO5IsFhmV4BESDE6ahoUvCkCARBwyV3RQ4Vn/EkarQRZN+NBM+/Pe/eio/B lB0ogqQ+vESbO4NbzXO/L92yMTFv3fsUYR1rRc+QxyMXbx0akcEweH3MqxuQxC1csdID HPCvh8y+SZAWWGLQmE0YPFccHuDvCt61g21r93yI/pCHhqDbqn5Hka1kBTA5HMRxShV+ tLtg== X-Gm-Message-State: AOJu0Yxif/cjh04tweHMBP43rUkPPoMZIp/iTQfXkghxxk2APM5Qa1Ge 8SeVKql5UWlNnweMXVzsXZToqNk67wTo/Y8ZtNhy6ZnffeP7UthupEkMEXTuuzI7YbNBE7bbG6G a1MJqQpEYiC1qQd3T4LF6Nj+boJi5fQP9 X-Gm-Gg: ASbGnct0EL8QTGV8i+EpiTkKW1r6cHIQC+9dLnJsifUd/tO8KJJlvn15pfTdpgponbN DLNDswtEIsgSF6N+AxCv/7QcKDA+UKFGRHk3B6LJ4er1kKkSjZg/1ujCcX3L2Xos5VYsksdxg0j P+L/84HX/Dbr+BaZCeTJCOnlxfJ4og X-Google-Smtp-Source: AGHT+IGfRryJjNXMTMRfrt1Ak025p+jZhTsGzn7mhPsOo3PU/RliCEl8prho0DWMltyQ2PSz8cEEI7mja/0xuoCi5hM= X-Received: by 2002:a05:6870:2b09:b0:2c1:2262:7941 with SMTP id 586e51a60fabf-2c23ea89d69mr1367499fac.16.1741255162246; Thu, 06 Mar 2025 01:59:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dominique Devienne Date: Thu, 6 Mar 2025 10:59:01 +0100 X-Gm-Features: AQ5f1Jp4m0IaBvOjfJI2uS5iclT2wD-NDAHE0vPj8ohgn3jEfLa_nQcogpFpu1w Message-ID: Subject: Re: psql and regex not like To: Ron Johnson Cc: pgsql-general Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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' ORDE= R BY datname; > > But it doesn't work so well from the bash prompt. Not escaping the "!" g= enerates a bunch of garbage, while escaping throws an sql syntax error. > > psql -Xc "select datname from pg_database WHERE datname \!~ 'template|pos= tgres' 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 ch= ange 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