# addAutoIncrement doesn't work for PostgreSQL

**URL:** <https://forum.liquibase.org/t/addautoincrement-doesnt-work-for-postgresql/528>\
**Category:** General Discussion\
**Created:** [May 16, 2010, 9:57am UTC](https://forum.liquibase.org/t/addautoincrement-doesnt-work-for-postgresql/528 "2010-05-16T09:57:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![florquinr](https://avatars.discourse-cdn.com/v4/letter/f/a87d85/32.png) [@florquinr](https://forum.liquibase.org/u/florquinr)\
**Post date:** [May 16, 2010, 9:57am UTC](https://forum.liquibase.org/t/addautoincrement-doesnt-work-for-postgresql/528/1 "2010-05-16T09:57:00Z")

</div>

Trying to use addAutoIncrement (LiquiBase version 1.9.5) with PostgreSQL (8.4.0),

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Auto increment the primary keys &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

I have the following error :

Reason: liquibase.exception.JDBCException: Error executing SQL ALTER TABLE cp1\_table ALTER COLUMN &nbsp;id SET DEFAULT 'cp1\_table\_id\_seq': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Caused By: Error executing SQL ALTER TABLE cp1\_table ALTER COLUMN &nbsp;id SET DEFAULT 'cp1\_table\_id\_seq': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Caused By: ERROR: invalid input syntax for integer: "cp1\_table\_id\_seq"

Should be:

ALTER TABLE cp1\_table ALTER COLUMN &nbsp;id SET DEFAULT NEXTVAL('cp1\_table\_id\_seq')

A workaround is to use a native sql directive to define the changeSet, it works but …

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Auto increment the primary keys (for PostgreSQL) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREATE SEQUENCE cp1\_table\_id\_seq; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ALTER TABLE cp1\_table alter COLUMN id set default nextval('cp1\_table\_id\_seq'); &nbsp; &nbsp; &nbsp; &nbsp;

Remark: the autoIncrement attribute works correctly for a createTable.

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [May 16, 2010, 9:57am UTC](https://forum.liquibase.org/t/addautoincrement-doesnt-work-for-postgresql/528/2 "2010-05-16T09:57:00Z")

</div>

Sorry for the slow reply.&nbsp; I created an issue for this ([http://liquibase.jira.com/browse/CORE-616)](http://liquibase.jira.com/browse/CORE-616)) and will get it fixed for the 2.0 release.&nbsp; You’ll have to use the work around for 1.9, or the modifySql tag to fix up the generated sql for postgres.

Nathan

---

<div class="post-metadata">

**Author:** ![florquinr](https://avatars.discourse-cdn.com/v4/letter/f/a87d85/32.png) [@florquinr](https://forum.liquibase.org/u/florquinr)\
**Post date:** [May 16, 2010, 9:57am UTC](https://forum.liquibase.org/t/addautoincrement-doesnt-work-for-postgresql/528/3 "2010-05-16T09:57:00Z")

</div>

Thanks
