Autoincrement in liquibase

让人想犯罪 __ 提交于 2020-03-02 09:19:27

问题


How do i set the autoincrement property using 'startWith' on a column in PostgreSQL using liquibase??

For some reason it always starts from 1. I tried using a custom sequence but that didn't help either.

<column autoIncrement="true" startWith="100" name="id" type="bigint">

That's my current column definition which does not work.

EDIT:

I want to import data from csv using liquibase. I tried the following:

<changeSet author="author" id="createSequence">
    <createSequence
                    incrementBy="1"
                    sequenceName="mytable_id_seq"
                    startValue="1000"/>
    </changeSet>
</changeSet>


<changeSet author="author" id="1-mytable">
    <createTable tableName="mytable">
        <column name="id" type="BIGSERIAL" defaultValueComputed="nextval('mytable_id_seq')">
              <constraints primaryKey="true" primaryKeyName="mytable_pkey"/>
        </column>
    </createTable>

    <loadData encoding="UTF-8"
              file="liquibase/data/mytable.csv"
              separator=","
              tableName="mytable">
    </loadData>
</changeSet>

If i try this I receive the following error 'currval of sequence "table_id_seq" is not yet defined in this session' and I think that it uses the sequence from the public schema instead of what i have set to liquibase.

  1. Another thing i tried was to update it manually:

ALTER SEQUENCE mytable_id_seq restart with 100;

In this case the sequence used was the one from the public schema, but i want to use the schema set to liquibase

来源:https://stackoverflow.com/questions/54948103/autoincrement-in-liquibase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!