ClickHouse/tests/queries/0_stateless/00952_basic_constraints.sh

55 lines
2.0 KiB
Bash
Raw Normal View History

2019-05-25 18:13:43 +00:00
#!/usr/bin/env bash
2019-05-26 08:43:45 +00:00
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
2020-08-01 00:51:12 +00:00
. "$CURDIR"/../shell_config.sh
2019-05-26 08:43:45 +00:00
2019-08-24 22:04:36 +00:00
EXCEPTION_TEXT=violated
EXCEPTION_SUCCESS_TEXT=ok
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS test_constraints;"
$CLICKHOUSE_CLIENT --query="CREATE TABLE test_constraints
(
a UInt32,
b UInt32,
CONSTRAINT b_constraint CHECK b > 0
)
ENGINE = MergeTree ORDER BY (a);"
# This one must succeed
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (1, 2);"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
# This one must throw and exception
2019-08-24 22:04:36 +00:00
2019-07-28 12:33:40 +00:00
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (3, 4), (1, 0), (3, 4), (6, 0);" 2>&1 \
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
$CLICKHOUSE_CLIENT --query="DROP TABLE test_constraints;"
# Test two constraints on one table
$CLICKHOUSE_CLIENT --query="CREATE TABLE test_constraints
(
a UInt32,
b UInt32,
2019-07-28 12:33:40 +00:00
CONSTRAINT a_constraint CHECK a < 10,
CONSTRAINT b_constraint CHECK b > 10
)
ENGINE = MergeTree ORDER BY (a);"
# This one must throw an exception
2019-05-26 23:57:18 +00:00
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (1, 2);" 2>&1 \
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
# This one must throw an exception
2019-07-28 12:33:40 +00:00
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (5, 16), (10, 11), (9, 11), (8, 12);" 2>&1 \
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
# This one must succeed
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (7, 18), (0, 11);"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
$CLICKHOUSE_CLIENT --query="DROP TABLE test_constraints;"