Skip to content

Test and if necessary repair issues inserting NULL to get a default value when a column has an explicit DEFAULT #148

@theory

Description

@theory

From the ClickHouse Docs:

The expression expr is optional. If it is omitted, the column type must be specified explicitly and the default value will be 0 for numeric columns, '' (the empty string) for string columns, [] (the empty array) for array columns, 1970-01-01 for date columns, or NULL for nullable columns.

Currently the binary driver refuses to insert a NULL into a non-Nullable column, but the http driver allows it. Add tests with explicit DEFAULT values on the ClickHouse tables and ensure that the http driver does the right thing when inserting a NULL (with and without a corresponding constraint on the foreign Postgres table).

Determine whether the binary driver behavior should be the same, and if so remove this block and fix issues accordingly:

/*
* Prevent insertion if the column isn't Nullable. This differs from the
* http engine, which isn't aware of Nullable but just sends values off,
* in which case ClickHouse inserts default values (e.g., 0 for numbers,
* "" for strings, etc.).
*
* XXX Do we want to consider rejecting NULL inserts when the Postgres
* `NOT NULL` constraint exits? And when it doesn't exist and the column
* is not nullable, do we want to send the default value instead? Dropping
* this block should do that.
*/
if (isnull && !nullable)
throw std::runtime_error(
"cannot append NULL to NOT NULL " + col->Type()->GetName() + " column"
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    data typesImprove data type supportdriversImprove binary and/or http driver support

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions