Re: Robust ways for checking allowed values in a column

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Robust ways for checking allowed values in a column
Date: 2022-01-25 14:25:04
Message-ID: CAKFQuwbhKUsPXwPvoPnh2Xv=g748y6UxigCOoNOUY=a7EhEv0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 25, 2022 at 6:56 AM Shaozhong SHI <shishaozhong(at)gmail(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ray O'Donnell 2022-01-25 14:26:44 Re: Robust ways for checking allowed values in a column
Previous Message Guillaume Lelarge 2022-01-25 14:16:06 Re: Robust ways for checking allowed values in a column