26

I have two table as following :

CREATE TABLE StudentMaster (
  sId      SERIAL,
  StudentName VARCHAR(50)
);

CREATE TABLE StudentClassMap (
  studnetId BIGINT UNSIGNED NOT NULL,
  studentClass VARCHAR(10),
  FOREIGN KEY (studnetId) REFERENCES StudentMaster (sId)
);

This is my insert query.

INSERT INTO StudentMaster (studentName) values ('Jay Parikh');

INSERT INTO StudentClassMap (studnetId, studentClass)
values ((SELECT sId from StudentMaster where studentName='Jay Parikh'),
        'M.Sc. 1st Year');

I want to define ChangeSet for thes queries in liquibase.

For First query ChangeSet will be :

<changeSet author="unknown" id="insert-example">
    <insert tableName="StudentMaster ">
        <column name="studentName" value="Jay Parikh"/>
    </insert>
</changeSet>

But I don't know how to define ChangeSet for another query.
Any help ? Thanks in advance.

1 Answer 1

55

Use the valueComputed attribute:

<changeSet author="unknown" id="insert-example-2">
    <insert tableName="StudentClassMap">
        <column name="studentId" valueComputed="(SELECT sId from StudentMaster where studentName='Jay Parikh')"/>
        <column name="studentClass" value="McSc. 1st Year"/>
    </insert>
</changeSet>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.