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.96) (envelope-from ) id 1vOxUS-00EkZ0-0H for pgsql-general@arkaria.postgresql.org; Fri, 28 Nov 2025 12:22:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vOxTR-00B9CU-28 for pgsql-general@arkaria.postgresql.org; Fri, 28 Nov 2025 12:21:17 +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.96) (envelope-from ) id 1vOxTR-00B9CI-12 for pgsql-general@lists.postgresql.org; Fri, 28 Nov 2025 12:21:17 +0000 Received: from mail-yw1-x1129.google.com ([2607:f8b0:4864:20::1129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vOxTP-001z1N-1x for pgsql-general@lists.postgresql.org; Fri, 28 Nov 2025 12:21:17 +0000 Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-789524e6719so26122757b3.1 for ; Fri, 28 Nov 2025 04:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764332473; x=1764937273; darn=lists.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=xScEQ8e4DHsoifwxdcpvLrSPncnuTXoGoLcytH7JBBA=; b=ctLr6Txhy3d6UumcMp3P8IxwDIeBuHktoGayDcyGgdtXOL+kElfxzoxbRoQcFWOuL5 9dGePthMtI5sIvjExV0PnlC/f7fQE4CrjoFjJgkEXWOEJ2eTdAd/E5LpbHSZQ7IWwey/ WYqXT2FIpSsuYQmZ+PwUIff3uhFHIyF7u0TKCzN3Zamy5BKqjCuNxDJrzG/8LRqdIizR 1A9X/zJ9EIRgmVc87dg7Doq1a9nUln5D6hZPSQj/NAie/FUGS8FWVB+fD2p2F8ZwWOSw yf7efJbRRXvAT22WnOKxz6hBhiERIBLR1MdbnTY/5dVKvCkRVrxQgUZohbsL9j8IRquh d+7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764332473; x=1764937273; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xScEQ8e4DHsoifwxdcpvLrSPncnuTXoGoLcytH7JBBA=; b=fKbGhAjR8ustdNThri9Cp68qYIBzo5F2tpNxPCKkGeXgHbzk4GGMPrvAi2izdtJ32e GOUx+FVtbqeiW+Lk2RGD8aUhCtmdW1KJWXJedYjZXAiGY+UGII0M0ofER52nVV552MLF 995dWfVsPRapJr4f9761SNUV5XtRehnC1qvBKh0vfK29kHzAPg8EEanr3EIfhYmgeuN+ /VaY0Eh39LhphVmZ6Fk9KErX6rEITtG1b8Ai0wiL2Xm5dUfhBkfxqyuwaS2ADKptl1Zf HXzuzkSOjOTOW0Sis5MwT6zH7k0gNykWmrqwTy6tbM2/o7Z+3A1n6Iq8uIPtZQpFwTTM jN9A== X-Gm-Message-State: AOJu0YzrGOaHVO3EcMm+cvzSoTUM1dO5bW7AdhrnRTGLJvOMzMS77FdR artYAxPcsLD5U0yRi6KYP8BrS/ZiqzYaDVNfxl7vmxNsFuV+PMjOL+a86tbsfU0mrG61zisgox5 lXZ4uwy0MTiLbvhMnW+FFFgxfbcycz8PaEamD X-Gm-Gg: ASbGncsaAaGQvncU+6AiGKURWms84JP/4Ffg7XfzikqTeDVfYKZqlihAWjz8TWuk8qH HnSPlYXD53yJAaMsjuQly+V4KXAl8+xSHyoHVZqyUEyjzO/1f8bbIW7IJBaeh63F80cIRBm06J3 xJ/RMEFuNNvA0pYXgCbhmxi3wo1hbon4eD4dm3JC8xRKJzGDfSPn9MZ6zdHtuZ5rY/GzSey1KTe /GAHRwRSicU48yBCuck1ouRJICxlRjflIf9ZyztpdZ6Z/er7GQYaM/WIiHHvdTvnJ9w5J5mnKei 12Muvy3IcYvFgEB84gBrgv38/uo4zC4= X-Google-Smtp-Source: AGHT+IF8u5PwVSNZHJmYoN7J4LVJTEU8Lf5S2InJEp62e41qPEZwhX/u4CB0RV7yIxzdTuf0EyACG15qCxsOCpBaChY= X-Received: by 2002:a05:690e:1c09:b0:63f:9fd6:94f5 with SMTP id 956f58d0204a3-642f8ddf5e1mr21895017d50.8.1764332472985; Fri, 28 Nov 2025 04:21:12 -0800 (PST) MIME-Version: 1.0 References: <20251126154844.e6e3d5c7f476cc966fc201f4@wanadoo.fr> <29ffee7e-40a8-f911-4419-24ba8558f5db@appl-ecosys.com> In-Reply-To: <29ffee7e-40a8-f911-4419-24ba8558f5db@appl-ecosys.com> From: Bernice Southey Date: Fri, 28 Nov 2025 12:20:37 +0000 X-Gm-Features: AWmQ_bkb67RppvJ8ltcPLB73S-D1xp9t_gcah2HkpRI3HKDXDegFPTrCCWQdUbY Message-ID: Subject: Re: Selecting all variations of job title in a list To: Rich Shepard Cc: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Rich Shepard wrote: > Learning postgres regexp is at the top of my list. It's well worth knowing a few regex tricks and they're surprisingly easy to remember. I find these the most useful for ad hoc queries. '|' for or as mentioned '()' if you want to check part of an expression eg '(abc|xyz)pqr' '^' to restrict it to the beginning '$' to restrict it to the end Here's an example with your list. with x(t) as (values ('Asst Gen Mgr.'), ('Env Mgr,'), ('Gen Mgr.'), ('Mgr,'),('Plant Mgr.')) select * from x where t ~ '(Asst Gen |Gen |Env |Plant |)Mgr(.|,)' Here's a slightly fancier nested one, just for illustration. with x(t) as (values ('Asst Gen Mgr.'), ('Env Mgr,'), ('Gen Mgr.'), ('Mgr,'),('Plant Mgr.')) select * from x where t ~ '^((Asst |)Gen |Env |Plant |)Mgr(.|,)$' I use regex in my tests and it's practically instant on a few thousand rows. Thanks, Bernice