Thread: Robust ways for checking allowed values in a column

Robust ways for checking allowed values in a column

From
Shaozhong SHI
Date:
I tried the following:

 select form from mytable  where form ~ '^Canal$|^Drain$|^Foreshore$|^inlandRiver$|^Lake$|^lockOrFlightOfLocks$|^Marsh$|^Researvoir$|^Sea$|^tidalRiver$|^Transfer$'

I used ^ and $ to ensure checking of allowed values.

However, 'Backyard' was selected.

Why is that?

Regards,

David

Re: Robust ways for checking allowed values in a column

From
Guillaume Lelarge
Date:
Le mar. 25 janv. 2022 à 14:56, Shaozhong SHI <shishaozhong@gmail.com> a écrit :
I tried the following:

 select form from mytable  where form ~ '^Canal$|^Drain$|^Foreshore$|^inlandRiver$|^Lake$|^lockOrFlightOfLocks$|^Marsh$|^Researvoir$|^Sea$|^tidalRiver$|^Transfer$'

I used ^ and $ to ensure checking of allowed values.

However, 'Backyard' was selected.

Why is that?


It works for me:

# select 'Backyard' ~ '^Canal$|^Drain$|^Foreshore$|^inlandRiver$|^Lake$|^lockOrFlightOfLocks$|^Marsh$|^Researvoir$|^Sea$|^tidalRiver$|^Transfer$';
┌──────────┐
│ ?column? │
├──────────┤
│ f        │
└──────────┘
(1 row)

So you will probably need a complete and reproducible example so that we could test it.


--
Guillaume.

Re: Robust ways for checking allowed values in a column

From
"David G. Johnston"
Date:
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.

Re: Robust ways for checking allowed values in a column

From
Ray O'Donnell
Date:
On 25/01/2022 13:55, Shaozhong SHI wrote:
> I tried the following:
> 
> select form from mytable  where form ~ 
>
'^Canal$|^Drain$|^Foreshore$|^inlandRiver$|^Lake$|^lockOrFlightOfLocks$|^Marsh$|^Researvoir$|^Sea$|^tidalRiver$|^Transfer$'
>
>  I used ^ and $ to ensure checking of allowed values.
> 
> However, 'Backyard' was selected.
> 
> Why is that?

Sounds like a candidate for a foreign key relationship.

Ray.


-- 
Raymond O'Donnell // Galway // Ireland
ray@rodonnell.ie



Re: Robust ways for checking allowed values in a column

From
Shaozhong SHI
Date:
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.

Re: Robust ways for checking allowed values in a column

From
Rob Sargent
Date:
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')