Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCOsT-0003nV-IH for pgsql-general@arkaria.postgresql.org; Tue, 25 Jan 2022 16:41:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCOsR-0007wO-Na for pgsql-general@arkaria.postgresql.org; Tue, 25 Jan 2022 16:41:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCOsR-0007uY-AG for pgsql-general@lists.postgresql.org; Tue, 25 Jan 2022 16:41:03 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nCOsM-0005uc-Nw for pgsql-general@lists.postgresql.org; Tue, 25 Jan 2022 16:41:02 +0000 Received: by mail-pj1-x102b.google.com with SMTP id h20-20020a17090adb9400b001b518bf99ffso2439927pjv.1 for ; Tue, 25 Jan 2022 08:40:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=yMkS5UkL+eiJ8p4U+mH6GBIkKOH7pNeuvbnQxzCf7jw=; b=iEPnPh4TyKjevRpvUzJCTaIuB8F6vo4G6GVM8JMeLL2GmxauZ+fmcD3TEJkzVIOfNB n9emTFXynpnK9slVnFzLm4nny0AqivPbiQdbFn4CNM/VltIzwG1Ev2zD4V9gE6eK5yaG 6wm6IO4oxzqbtRXsTLL/qiJNYZeQQORi6xvwwtJxbpmuTuGPRzztJgG+2hz+KSwd6gt6 nM/NNR0nvWA3XqBG3X/YGozH++FpKd/9EZmXfns0nsdl2myLrPxhBrJUK9pbdmH3Ns14 7Iz1Msl/YT7S2qV20pa8vxk5nrqbRzU9F4uiLUcl1d+JwsNQ+RpUg3KPCERWX0oIEqt6 5DeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=yMkS5UkL+eiJ8p4U+mH6GBIkKOH7pNeuvbnQxzCf7jw=; b=VUiqZvYLHh5D8IGbekxMUYCvOula/Sz/LJ9S64CpVYbLW1l6CNFB4bL6tgb9lcu9ZE Dubmow+NCduRZ3jyIV2gAoPuLbXcwao+szxEOjtkQvzUVOX7TVhXf0W4Yd8JxuMq7dy3 9sO/H/iDXQ/WBskxzK/8EqLjwLbzJYowyqRdfi+GHPHj0Ts/tE3X3UeGVpJ3M5fJamDx u3aAjbkCOFKV7kQe9a2LV061c1gnHrNWHYrQuoAnIvhDCNMy7/RknWsB2Uh97J2Ka0t+ KI7dDEOx1SonXZgsMb9S92gRhhlVVQMrVSW+/ZBfE11plVyn79hs4YSfnSp7dR+FqmNc CNYA== X-Gm-Message-State: AOAM533pCmli6ddmkm9WgArxolggDJ+16eXsKZ+cwkUnQlHp/yt6yNLc njRxHHieLrQvpYImBCa6MaC2FNkxpEo= X-Google-Smtp-Source: ABdhPJx3WEQQs5VJ2mSmucJl7XZagDPpbKIMmJad7nk4XWCyXIvjixPs+HzPNwIH6w5IrQVTExTl4Q== X-Received: by 2002:a17:903:22c9:b0:14b:2c4e:5c35 with SMTP id y9-20020a17090322c900b0014b2c4e5c35mr15399577plg.10.1643128855495; Tue, 25 Jan 2022 08:40:55 -0800 (PST) Received: from [10.0.0.18] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id y15sm8834928pfi.87.2022.01.25.08.40.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jan 2022 08:40:55 -0800 (PST) Content-Type: multipart/alternative; boundary="------------ia01HI7TJc9b7eKtvCbYWPsw" Message-ID: <7bcf6809-a959-5224-93db-645d15cd4359@gmail.com> Date: Tue, 25 Jan 2022 09:40:53 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: Robust ways for checking allowed values in a column Content-Language: en-CA To: pgsql-general@lists.postgresql.org References: From: Rob Sargent In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------ia01HI7TJc9b7eKtvCbYWPsw Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/25/22 09:35, Shaozhong SHI wrote: > How about adding null as an alteration. > > Would this be robust? > > Regards, > > David > > On Tue, 25 Jan 2022 at 14:25, David G. Johnston > wrote: > > On Tue, Jan 25, 2022 at 6:56 AM Shaozhong SHI > wrote: > >  select form from mytable  where form ~ > '^Canal$|^Drain$|^Foreshore$|^inlandRiver$|^Lake$|^lockOrFlightOfLocks$|^Marsh$|^Researvoir$|^Sea$|^tidalRiver$|^Transfer$' > > > You do not need to repeat the boundary metacharacters on each > branch.  You can assert their presence just once and then use > parentheses to group the alternations. > > form ~ '^(?Canal|Drain|etc...)$' > > David J. > You would need to add form ~ 'expression' or form is null And a body of held water is a reservoir (no 'a') --------------ia01HI7TJc9b7eKtvCbYWPsw Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 1/25/22 09:35, Shaozhong SHI wrote:
How about adding null as an alteration.

Would this be robust?

Regards,

David

On Tue, 25 Jan 2022 at 14:25, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Tue, Jan 25, 2022 at 6:56 AM Shaozhong SHI <shishaozhong@gmail.com> wrote:
 select form from mytable  where form ~ '^Canal$|^Drain$|^Foreshore$|^inlandRiver$|^Lake$|^lockOrFlightOfLocks$|^Marsh$|^Researvoir$|^Sea$|^tidalRiver$|^Transfer$'

You do not need to repeat the boundary metacharacters on each branch.  You can assert their presence just once and then use parentheses to group the alternations.

form ~ '^(?Canal|Drain|etc...)$'

David J.


You would need to add form ~ 'expression' or form is null

And a body of held water is a reservoir (no 'a')
--------------ia01HI7TJc9b7eKtvCbYWPsw--