Skip to content

Table created with non-nullable column even without NOT NULL in column definition #963

@tsegismont

Description

@tsegismont

When using the MS SQL Client for CREATE TABLE statements, the resulting columns are non-nullable even when NOT NULL is not specified on the column definition.

This does not happen when using the JDBC client on the same database.

PreparedStatement create = conn.prepareStatement("create table Basic (id int, dessimal numeric(19,2), primary key (id))");
create.executeUpdate();
PreparedStatement insert = conn.prepareStatement("INSERT INTO Basic (id, dessimal) values (3, ?)");
insert.setBigDecimal(1, new BigDecimal("3.2"));
insert.executeUpdate();

The snippet above works fine but this one fails:

connnection.preparedQuery("create table Basic2 (id int, dessimal numeric(19,2), primary key (id))")
  .execute(ctx.asyncAssertSuccess(create -> {
    connnection.preparedQuery("INSERT INTO Basic2 (id, dessimal) values (3, @p1)")
      .execute(Tuple.of(NullValue.BigDecimal), ctx.asyncAssertSuccess());
  }));

The error message is:

io.vertx.mssqlclient.MSSQLException: {number=515, state=2, severity=16, message='Cannot insert the value NULL into column 'dessimal', table 'master.dbo.Basic2'; column does not allow nulls. INSERT fails.', serverName='0ac9600ef0bb', lineNumber=1}

As a workaround, the column definition must explicitly allow NULL values:

create table Basic2 (id int, dessimal numeric(19,2) null, primary key (id))

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions