M
M
Melnik2282021-03-29 12:42:17
PostgreSQL
Melnik228, 2021-03-29 12:42:17

Why is the rule not created with IF?

I'm trying to create a rule so that the values ​​​​in the field begin only with Russian letters (both with update and with insert later),
HXrMMLl.jpg
but for some reason it swears at IF

CREATE OR REPLACE RULE name_rule_update AS
    ON UPDATE TO public.abonents
    WHERE (NEW.last_name != OLD.last_name)
    DO INSTEAD
(IF NEW.last_name NOT LIKE '[А-я]%' THEN
  RAISE NOTICE 'Фамилия абонента может начинаться только с русской буквы';
END IF);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2021-03-29
@melkij

Why did you decide that such a syntax exists?
Why did you decide that you need a rule?
You need a check constraint.
For a localized message to the user, check on the backend of your application. Well, or, if you really want to, prohibit direct changes to tables and communicate with the database user only through storage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question