From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: How to restrict
Date: Tue, 26 Feb 2019 17:18:21 +0200
Message-ID: <11341ee7-23e6-adfb-b14f-218eeffa8102@matrix.gatewaynet.com> (raw)
In-Reply-To: <6C004315-7728-4909-BCCD-2DE8F5DA3920@illinois.edu>
References: <6C004315-7728-4909-BCCD-2DE8F5DA3920@illinois.edu>
On 26/2/19 5:11 μ.μ., 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?
>
Easy with a CHECK CONSTRAINT, like :
create table baba (type varchar(10) CHECK (type in ('X','Y','Z')));
>
> Thanks,
>
> *LANCE CAMPBELL <https://directory.illinois.edu/person/lance>*
>
> /Software Architect/
>
> Web Services <https://webtools.illinois.edu/;
>
> Public Affairs <https://publicaffairs.illinois.edu/;
>
> Contact the Webtools Team <https://go.illinois.edu/contactUs;
>
> 217.333.0382
>
> lance@illinois.edu <mailto:lance@illinois.edu>
>
> /var/folders/wp/1f6l7hw95y718z976kgnl5f9kr5rtc/T/com.microsoft.Outlook/WebArchiveCopyPasteTempFiles/signature_logo.png <http://illinois.edu/;
>
> /Under the Illinois Freedom of Information Act any written communication to or from university employees regarding university business is a public record and may be subject to public disclosure./
>
--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
Attachments:image001.png (image/png, 2.5K) downloadview image
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: achill@matrix.gatewaynet.com, pgsql-admin@lists.postgresql.org
Subject: Re: How to restrict
In-Reply-To: <11341ee7-23e6-adfb-b14f-218eeffa8102@matrix.gatewaynet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox