M
M
Melnik2282021-03-30 16:16:25
PostgreSQL
Melnik228, 2021-03-30 16:16:25

Why is the limit not working?

you need to set a limit on the field so that it can take only those values ​​\u200b\u200bthat would begin with a Russian letter
, so I create

ALTER TABLE abonents
ADD CONSTRAINT last_name_check
CHECK (last_name LIKE '[А-я]%') NOT VALID;

I see that everything is attached,
az0KpBZ.jpg
but nothing works, does not allow me to insert any lines
yhjJoAr.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2021-03-30
@Melnik228

They wrote that last_name should start with the string [А-з] - this is how it is checked.

melkij=> select '[A]ds' like '[A]%';
?column?
----------
t
(1 line)

Where do you need a query rewrite system if you do not distinguish regular expressions from like?
Why not valid is better I won’t even ask.

V
Victoriousya, 2021-05-11
@Victoriousya

Colleagues, the person simply confused the syntax for SIMILAR TO expressions and for LIKE expressions.
correct syntax

ALTER TABLE abonents
ADD CONSTRAINT last_name_check
CHECK (last_name SIMILAR TO '[А-я]%');

Although I am an adherent of the usual regexp and would write like this.
ALTER TABLE abonents
ADD CONSTRAINT last_name_check
CHECK (last_name ~ '[А-я].*');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question