24

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.

unknown
  • 4,859
  • 10
  • 44
  • 62

1 Answers1

53

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>
Chris Williams
  • 11,647
  • 15
  • 60
  • 97
Nathan Voxland
  • 15,453
  • 2
  • 48
  • 64