Re: How to restrict

From: Shreeyansh Dba <shreeyansh2014(at)gmail(dot)com>
To: Ron <ronljohnsonjr(at)gmail(dot)com>
Cc: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: How to restrict
Date: 2019-02-26 15:39:01
Message-ID: CAGDYbUPGzgYiQS0d0oj_yOk5MHfc4gdyvGMet8rhALDA06AGwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Yes, @Ron reply makes sense you can use a CHECK constraint or FOREIGN KEY.

Thanks & Regards,
*Shreeyansh DBA Team*
www.shreeyansh.com

On Tue, Feb 26, 2019 at 8:54 PM Ron <ronljohnsonjr(at)gmail(dot)com> wrote:

> On 2/26/19 9:11 AM, Campbell, Lance wrote:
>
> PostgreSQL 10.x
>
>
>
> What is the best way to restrict the values on a text field to make sure
> they only contain particular values: Example: The field “type” can only
> contain the values of “X”, “Y” and “Z”. Would a trigger be the best
> strategy? Or is there a special SQL type I should use in this particular
> case?
>
>
> Use either a CHECK constraint or FOREIGN KEY.
>
> For just a few items*, *understanding that you must drop and recreate the
> constraint to modify it.
> http://www.postgresqltutorial.com/postgresql-check-constraint/
> CREATE TABLE foo
> (
> bar VARCHAR(20) CHECK (bar IN ('X', 'Y', 'Z'))
> );
>
> For more items, and simpler additions:
> http://www.postgresqltutorial.com/postgresql-foreign-key/
>
> --
> Angular momentum makes the world go 'round.
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message gilberto.castillo 2019-02-26 15:46:14 Re: [MASSMAIL]Re: pg_dumpall: could not connect to database: FATAL
Previous Message Pepe TD Vo 2019-02-26 15:36:08 Re: [MASSMAIL]Re: pg_dumpall: could not connect to database: FATAL