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 1tsqPf-0062kK-GE for pgsql-general@arkaria.postgresql.org; Thu, 13 Mar 2025 21:48:23 +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 1tsqPd-006f5p-T9 for pgsql-general@arkaria.postgresql.org; Thu, 13 Mar 2025 21:48:21 +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 1tsqPd-006f5g-He for pgsql-general@lists.postgresql.org; Thu, 13 Mar 2025 21:48:21 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tsqPa-002irf-0F for pgsql-general@postgresql.org; Thu, 13 Mar 2025 21:48:21 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-300f92661fcso2538160a91.3 for ; Thu, 13 Mar 2025 14:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741902497; x=1742507297; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=d6URPv++geXmDU9hdJh77x9tQIKf+pm4wKXNeoRr6BY=; b=Iq7wZDalo8cGjY/tCyQJB1JS0h2CV2ZMXZjSQUYeMpdgULM0lNN4m2yq55UDFL0ZIO VZ3dIFlaB3CKAyFM7Yst7hgMObytgxCxqwLzU8VOMi97WzlU1oxxHp80VPjOBPsPuBpj fm+fXJNpq/7oaNRlT5lL5ETZErmfW/nteJB0LDPxErT9njDCYhxPcPc6ToiifK7+c+H5 9F0gtATLQsGgYrkuNM8y2dY3fUkIwwnaWCkAm8rt9l4auOyEGJ3HPbChZ05PBQWER/X3 wtEQKcI3VsxwIi/ouGOU1dFlxOI1ou+AzbuYFtnG+DgN4g1AGVCMY474vRKJLYgBxuk9 fA+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741902497; x=1742507297; h=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=d6URPv++geXmDU9hdJh77x9tQIKf+pm4wKXNeoRr6BY=; b=XLsDF4a+8t2Nu/cV00ZjYEc6w5ViaYvC2v10cvnCTdbkBoLA/lGvM3rRhLbdK5MTDH 5X0LtmE5huk/mmzroNlDvn/NHUu/zbC2fbo65n16/KLFZbLQJKlKc3SzrQECoNK/RT3B BhTz/AW1z7X7ycmpZ8bBk/mgJXG1FBkhEAKr5iiRSmGxtRNBZwARfykTZ7KahnXspaDQ nt70qkmAcm/Ouffk/isILzPKJIxLGelR9bnG7hiY01MrD0hVOm4AGKAn1wJWDTGFCUES UVFwe+1+5CrSxjv3WK49cDkdXzH3IRp1AkalclQ+agImlzq6j0BjVV7bFmu2unvOr9PD NEfA== X-Gm-Message-State: AOJu0YxWnIHcpmHV/tWGNU89P/OgWCmqI4Ka4EtYXQTdphi4ja0meX2+ 5Kk4ctanz1JFV/mT0fI77xAvTciDHQXlVP4L9EObz69ILmfXISNPqZcLve/V+tIFViaf4NLShin hv2zha/lPLVlDHlusEIucBIimpdogRQs5 X-Gm-Gg: ASbGnctMrtjDOdx8e+ddp56Tz3t0Cjb4LCdjjr1PAIEH3V2SiHH3JA6Veo4qZkr+D0I vabUgWemVty0p/yIfuD2JfKybM6y6zXkKke6ps9eBi5nOcwMOuLgjCod4z0Bshk1e2tYlNIH50i jdVkmsuxm7mS+IRtCjlGv6epaOL07Q X-Google-Smtp-Source: AGHT+IHswhhcUkdZjingwgD/BzJAVgyCwxsQ6kyryhqig9bv0OmwAsC5hcmbXqArgrnvFpmG8GRdGUlfFwvGvC71lyg= X-Received: by 2002:a17:90a:fc43:b0:2ff:618c:a1e9 with SMTP id 98e67ed59e1d1-30151d54e0amr108660a91.23.1741902497160; Thu, 13 Mar 2025 14:48:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Renan Alves Fonseca Date: Thu, 13 Mar 2025 22:48:05 +0100 X-Gm-Features: AQ5f1JqAj78tJDxWOKnWRLJrLoE6U-362OTmr5TGfQ7z8Rs-UT2Un4_f1Y9-fkE Message-ID: Subject: Re: psql and regex not like To: Ron Johnson Cc: pgsql-general Content-Type: multipart/alternative; boundary="00000000000093aaa306304047e1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000093aaa306304047e1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Another dirty hack: MAGIC=3D\! psql -Xc "select datname from pg_database WHERE datname $MAGIC~ 'template|postgres' ORDER BY datname;" Em qui., 6 de mar. de 2025 =C3=A0s 10:38, Ron Johnson escreveu: > 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 "!" > 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 , and butter sauce. > Don't boil me, I'm still alive. > lobster! > --00000000000093aaa306304047e1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Another dirty hack:

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

Em qui., 6 de mar. de 20= 25 =C3=A0s 10:38, Ron Johnson <ronljohnsonjr@gmail.com> escreveu:
This statement runs great= from the psql prompt.=C2=A0 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.=C2=A0 Not escapi= ng the "!" generates a bunch of garbage, while escaping throws an= sql syntax=C2=A0error.

p= sql -Xc "select datname from pg_database WHERE datname \!~ 'templa= te|postgres' ORDER BY datname;"
ERROR: =C2=A0syntax error at or= near "\"


What's the magi= c=C2=A0syntax?

(Yes, I could create a view and the= n query the view, but I'm going to be running this remotely against doz= ens of servers, so I don't want to have to create dozens of views,=C2= =A0then need to recreate them every time I want to change the=C2=A0query.)<= /div>

--
Death to <Reda= cted>, and butter sauce.
Don't boil me, I'm still alive.
=
<Redacted> lobster!
--00000000000093aaa306304047e1--