Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert new data using Liquibase, postgreSQL and sequence

How do I make an insert for PostgreSQL using Liquibase if my ids are sequential. I try with the following:

<changeSet author="rparente" id="service-1.1-2019-01-09-01">
        <insert tableName="tenant">
            <column name="id"defaultValueSequenceNext="hibernate_sequence"/>
            <column name="description" value="Prueba"/>
            <column name="name" value="antel"/>
            <column name="service_id" value="antel"/>
        </insert>
    </changeSet>

and I try with

<changeSet author="rparente" id="service-1.1-2019-01-09-01">
        <insert tableName="tenant">
            <column name="id"  value="nextval('hibernate_sequence')"/>
            <column name="description" value="Prueba"/>
            <column name="name" value="antel"/>
            <column name="service_id" value="antel"/>
        </insert>
    </changeSet>

The error is:

ERROR: null value in column "id" violates not-null constraint

like image 377
Renzo Parente Avatar asked Jan 10 '19 15:01

Renzo Parente


1 Answers

I found the solution to insert data in Postgres with sequence (no default) ids

<changeSet author="author_name" id="service-1.1-2019-01-09-01"> 
    <insert tableName="tenant"> 
        <column name="id" valueSequenceNext="name_sequence"/> 
        <column name="description" value="TEST"/> 
        <column name="name" value="test"/> 
        <column name="service_id" value="testl"/> 
        <column name="status" value="ACTIVE"/> 
    </insert> 
</changeSet>
like image 163
Renzo Parente Avatar answered Dec 02 '22 15:12

Renzo Parente