我希望有一些建议。我正在使用CSV文件中的五条记录完成一个表的简单加载。当我打开桌子上,我得到了错误的下面:使用<loadUpdateData>从CSV文件加载数据Postgres
liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: ERROR: zero-length delimited identifier at or near """"
这是CSV文件
1,Nate Happy,[email protected],1761 Brookview Trail,(205) 555-1212
2,Brigette Happy,[email protected],7507 Meadowgate Lane,(704) 555-1212
3,Katie Happy,[email protected],7507 Meadowgate Lane,(704) 555-1212
4,Lauren Happy,[email protected],7507 Meadowgate Lane,(704) 555-1212
5,Jackson Hope,[email protected],7507 Meadowgate Lane,(704) 555-1212
这是我的变更用于加载数据
<changeSet id="6-loadData" author="liquibase" dbms="postgresql" >
<preConditions onErrorMessage="Failed Pre Conditions for table" onFail="HALT">
<and>
<tableExists schemaName="public" tableName="contact" />
<sqlCheck expectedResult ="1">SELECT COUNT(*) contact</sqlCheck>
</and>
</preConditions>
<comment>Adding Data...</comment>
<loadUpdateData catalogName="pg_catalog"
encoding="UTF-8"
file="src/main/resources/data/contacts.csv"
primaryKey="contact_id"
quotchar="A String"
schemaName="public"
separator=","
tableName="contact">
<column name="contact_id" type="int" />
<column name="contact_name" type="varchar(45)"/>
<column name="email" type="varchar(45)" />
<column name="address" type="varchar(45)" />
<column name="telephone" type="varchar(45)" />
</loadUpdateData>
这是我创建表的变更集:
<changeSet id="4 Create Table" author="liquibase" runAlways="true">
<preConditions onErrorMessage="Failed Pre Conditions for table" onFail="MARK_RAN">
<not><tableExists schemaName="public" tableName="contact"/> </not>
</preConditions>
<comment>Creating Table named: Contact...</comment>
<createTable tableName="contact" schemaName="public">
<column name="contact_id" type="int" >
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="contact_name" type="varchar(45)">
<constraints nullable="false"/>
</column>
<column name="email" type="varchar(45)">
<constraints nullable="false"/>
</column>
<column name="address" type="varchar(45)">
<constraints nullable="false"/>
</column>
<column name="telephone" type="varchar(45)">
<constraints nullable="false"/>
</column>
</createTable>
这里是我使用的主键序列(CONTACT_ID)
<changeSet id="2-Create Sequence" author="liquibase" runAlways="true">
<preConditions onErrorMessage="Failed Pre Conditions for sequence" onFail="MARK_RAN">
<not><sequenceExists schemaName="public" sequenceName="contactid_seq" /></not>
</preConditions>
<comment>Creating Sequence...</comment>
<createSequence sequenceName="contactid_seq"
incrementBy="1"
minValue="1"
maxValue="9223372036854775807"
startValue="1"
ordered="1"
schemaName="public"/>
这是我如何使用约束:
<changeSet id="5-Add Constraint" author="liquibase">
<comment>Adding contactid_seq sequence to Contact table...</comment>
<addDefaultValue catalogName="pg_catalog"
columnDataType="int"
columnName="contact_id"
tableName="contact"
schemaName="public"
defaultValueSequenceNext="contactid_seq" />
感谢您花时间阅读我的文章。
Russ