I am trying to create a change set that inserts XML into a column in our database but liquibase doesn’t seem to like it. I’ve tried encoding < and > characters but no joy. Anyone else succeeded in doing this
I am trying to create a change set that inserts XML into a column in our database but liquibase doesn’t seem to like it. I’ve tried encoding < and > characters but no joy. Anyone else succeeded in doing this
I’m going to assume you are using XML file format. You can use CDATA to insert XML into a table:
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet id="insert_xml_into_test_department" author="BOB">
<sql>
<![CDATA[
INSERT INTO test_department (employee_number, department_name)
VALUES ('1', '<yourXML><data>Example</data></yourXML>');
]]>
</sql>
<rollback>
DELETE FROM test_department
WHERE employee_number = '1';
</rollback>
</changeSet>
</databaseChangeLog>
In sql format:
--liquibase formatted sql
--changeset BOB:insert_xml_into_test_country stripComments:false
INSERT INTO test_country (country_number, country_name)
VALUES ('1', --county_number
'<yourXML><data>Example</data></yourXML>') --country_name
;
/* liquibase rollback
DELETE FROM test_country where country_number = '1';
*/
In yaml format:
databaseChangeLog:
- changeSet:
id: insert_xml_into_test_city
author: doaksec
comment: Insert XML into the test_city table
context: dev
changes:
- sql:
sql: insert into test_city (id,city_name, mayor) values (1,'Portland','<yourXML><data>Example</data></yourXML>');
rollback:
- sql:
sql: delete from test_city where id = 1;