diff --git a/dbms/programs/client/Client.cpp b/dbms/programs/client/Client.cpp index 1b3519b5777..08358f5d135 100644 --- a/dbms/programs/client/Client.cpp +++ b/dbms/programs/client/Client.cpp @@ -1026,19 +1026,20 @@ private: while (true) { Block block = async_block_input->read(); - /// Check if server send Exception packet + auto packet_type = connection->checkPacket(); + /// Check if server send Log packet + if (packet_type && *packet_type == Protocol::Server::Log) + receiveAndProcessPacket(); + + /// Check if server send Exception packet + packet_type = connection->checkPacket(); if (packet_type && *packet_type == Protocol::Server::Exception) return; connection->sendData(block); processed_rows += block.rows(); - /// Check if server send Log packet - packet_type = connection->checkPacket(); - if (packet_type && *packet_type == Protocol::Server::Log) - receiveAndProcessPacket(); - if (!block) break; } diff --git a/dbms/tests/queries/0_stateless/00995_exception_while_insert.reference b/dbms/tests/queries/0_stateless/00995_exception_while_insert.reference new file mode 100644 index 00000000000..f74a124f5cc --- /dev/null +++ b/dbms/tests/queries/0_stateless/00995_exception_while_insert.reference @@ -0,0 +1 @@ +Got exception on client. diff --git a/dbms/tests/queries/0_stateless/00995_exception_while_insert.sh b/dbms/tests/queries/0_stateless/00995_exception_while_insert.sh new file mode 100755 index 00000000000..c9a531fafcf --- /dev/null +++ b/dbms/tests/queries/0_stateless/00995_exception_while_insert.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. $CURDIR/../shell_config.sh + +$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS check;" + +$CLICKHOUSE_CLIENT --query="CREATE TABLE check (x UInt64, y UInt64 DEFAULT throwIf(x > 10000000)) ENGINE = Memory;" + +seq 1 11000000 | $CLICKHOUSE_CLIENT --query="INSERT INTO check(x) FORMAT TSV" 2>&1 | grep -q "Value passed to 'throwIf' function is non zero." && echo "Got exception on client." ||: + +$CLICKHOUSE_CLIENT --query="DROP TABLE check;"