Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe8ff6b

Browse files
authored
Update TODO.md
1 parent 4276277 commit fe8ff6b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎functions/db_validation/TODO.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@
8989
where last_value is not null /*null means access denied*/ and used_percent > 33
9090
order by used_percent desc;
9191
```
92+
1. Ограничение с условиями между разными колонками на уровне строки таблицы смотрится понятнее. Пример:
93+
```sql
94+
CREATE TABLE test.test1
95+
(
96+
day_from int check(day_from >= 0 and coalesce(day_from, day_to) is not null),
97+
day_to int check(day_to >= 0 AND day_from <= day_to)
98+
);
99+
--vs
100+
CREATE TABLE test.test2
101+
(
102+
day_from int check(day_from >= 0),
103+
day_to int check(day_to >= 0), --тут запятая!
104+
check (coalesce(day_from, day_to) is not null and day_from <= day_to)
105+
);
106+
-- TEST
107+
insert into test.test1 values (null, null); --error
108+
insert into test.test1 values (1, null); --ok
109+
insert into test.test1 values (null, 1); --ok
110+
insert into test.test1 values (1, 2); --ok
111+
insert into test.test1 values (2, 1); --error
112+
```
92113

93114
# TODO валидация потенциальных ошибок в SQL запросах
94115

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /