Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot insert data into the table with ' ' (space) in one of its column name. #30

@pakapor

Description

@pakapor

From one of the example cases, if I put the column name test id and run the insert function, the program throws the exception.

Example Code:

#include <clickhouse/client.h>
using namespace clickhouse;

/// Initialize client connection.
Client client(ClientOptions().SetHost("localhost"));

/// Create a table.
client.Execute("CREATE TABLE IF NOT EXISTS test.numbers (\`test id\` UInt64, name String) ENGINE = Memory");

/// Insert some values.
try {
	Block block;

	auto id = std::make_shared<ColumnUInt64>();
	id->Append(1);
	id->Append(7);

	auto name = std::make_shared<ColumnString>();
	name->Append("one");
	name->Append("seven");

	block.AppendColumn("test id"  , id);
	block.AppendColumn("name", name);

	client.Insert("test.numbers", block);
} catch (std::exception &e) {
	printf("Error: %s\n", e.what());
}

Error: DB::Exception: Syntax error: failed at position 33: id,name ) VALUES. Expected one of: token, ClosingRoundBracket, Comma, Dot

I then tried putting ' " and ` around the column name for the data block, it throws on another line instead.

block.AppendColumn("`test id`" , id);

Error: DB::Exception: Not found column test id in block. There are only columns: test id, name

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions