question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It is no longer possible to create calculated columns on mssql

See original GitHub issue

Environment

Liquibase Version: 4.6.1

Liquibase Integration & Version: maven

Liquibase Extension(s) & Version:

  • liquibase-hibernate5: 4.6.1

Database Vendor & Version:

  • Microsoft SQL Server Developer (64-bit) 15.0.2080.9

Operating System Type & Version:

  • Windows 10 Pro (10.0)

Description

Liquibase 4.6.1 (and lower?) seems to require a value for the type property for the column specified in a addColumn change, this prevents the possibility to create a computed column on mssql as the generated SQL statement leads to a syntax error

Steps to reproduce

The following changeset worked with Liquibase 4.3.5:

<changeSet id="20200123095600-1" author="me" dbms="mssql">
    <addColumn tableName="event">
        <column name="payload_id AS JSON_VALUE(payload,'$.id')"
                       type=""
                       computed="true">
        </column>
    </addColumn>
    <createIndex tableName="event" indexName="idx_payload_id">
        <column name="payload_id"/>
    </createIndex>
</changeSet>

But, 4.6.1 gives me the following error:

liquibase.exception.ValidationFailedException: Validation Failed:
     1 changes have validation failures
          columnType is empty, config/liquibase/changelog/20200123110200_create_index_entity_Event.xml::20200123095600-1::me

It complains that the type attribute of the column specified in the addColumn change is empty.
If I specify the correct type as follows…

        <column name="payload_id AS JSON_VALUE(payload,'$.id')"
                       type="nvarchar(4000)"
                       computed="true">
        </column>

…Liquibase compiles it to the following SQL statement, which leads to a syntax error on mssql:

[Failed SQL: (102) ALTER TABLE event ADD payload_id AS JSON_VALUE(payload,'$.id') nvarchar(4000)]

Expected/Desired Behavior

I expect the pre-existing addColumn block for creating computed columns on mssql to be working even in 4.6.1, either without specifying the type property or by correctly specifying it and having the generated SQL statement to be correct.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yodzhubeiskyicommented, Feb 11, 2022

This issue is fixed by #2340

0reactions
nickshoecommented, Feb 15, 2022

Thanks @yodzhubeiskyi, I’ll try it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specify Computed Columns in a Table - SQL Server
In Object Explorer, expand the table for which you want to add the new computed column. Right-click Columns and select New Column. Enter...
Read more >
An overview of computed columns in SQL Server - SQLShack
A computed column in SQL Server is a virtual column that computes its values from an expression. We can use a constant value,...
Read more >
tsql - How do you add a computed column to a Table?
The syntax I was looking for is: alter table TABLE_NAME add [column_name] as (**COLUMN-SQL**).
Read more >
Computed Columns In SQL Server - C# Corner
A computed column is computed from an expression that can use other columns in the same table. The expression can be a non-computed...
Read more >
Unable to ALTER Computed Column in SQL Server
A: There is NO way to alter computed column. You will have to drop and recreate it. Here is a demonstration of it....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found