Re: How to restrict

Поиск
Список
Период
Сортировка
От Ron
Тема Re: How to restrict
Дата
Msg-id 27032520-e411-6506-a0ca-eaf258524ffe@gmail.com
обсуждение исходный текст
Ответ на How to restrict  ("Campbell, Lance" <lance@illinois.edu>)
Ответы Re: How to restrict  (Shreeyansh Dba <shreeyansh2014@gmail.com>)
Список pgsql-admin
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.

В списке pgsql-admin по дате отправления:

Предыдущее
От: gilberto.castillo@etecsa.cu
Дата:
Сообщение: Re: [MASSMAIL]Re: pg_dumpall: could not connect to database: FATAL
Следующее
От: Pepe TD Vo
Дата:
Сообщение: Re: [MASSMAIL]Re: pg_dumpall: could not connect to database: FATAL