K
K
Kirill2021-03-05 13:13:04
PostgreSQL
Kirill, 2021-03-05 13:13:04

How to check the value of a string?

I need to remember the gender of a person, so I add another column.
Because there will not be more than 2 genders on the site I want to check the line for a match (male or famale).

In my opinion it should look like this:

ALTER TABLE product ADD COLUMN gender VARCHAR(6) CHECK ('male' or 'female');


I can't figure out the CHECK syntax, please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-03-05
@BPL

Using VARCHAR(6) for the gender field is not rational. Use ENUM('mail'. 'femail') or even BOOLEAN

R
Rsa97, 2021-03-05
@Rsa97

https://habr.com/ru/post/353556/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question