Robust ways for checking allowed values in a column

Started by Shaozhong SHIabout 4 years ago6 messagesgeneral
Jump to latest
#1Shaozhong SHI
shishaozhong@gmail.com

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

#2Guillaume Lelarge
guillaume@lelarge.info
In reply to: Shaozhong SHI (#1)
Re: Robust ways for checking allowed values in a column

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.

#3David G. Johnston
david.g.johnston@gmail.com
In reply to: Shaozhong SHI (#1)
Re: Robust ways for checking allowed values in a column

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.

#4Ray O'Donnell
ray@rodonnell.ie
In reply to: Shaozhong SHI (#1)
Re: Robust ways for checking allowed values in a column

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

#5Shaozhong SHI
shishaozhong@gmail.com
In reply to: David G. Johnston (#3)
Re: Robust ways for checking allowed values in a column

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:

Show quoted text

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.

#6Rob Sargent
robjsargent@gmail.com
In reply to: Shaozhong SHI (#5)
Re: Robust ways for checking allowed values in a column

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')