# PostgreSQL - Queries and Primary Keys

**URL:** <https://forum.inductiveautomation.com/t/postgresql-queries-and-primary-keys/39425>\
**Category:** Ignition\
**Created:** [October 6, 2020, 3:46pm UTC](https://forum.inductiveautomation.com/t/postgresql-queries-and-primary-keys/39425 "2020-10-06T15:46:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [October 6, 2020, 3:46pm UTC](https://forum.inductiveautomation.com/t/postgresql-queries-and-primary-keys/39425/1 "2020-10-06T15:46:39Z")

</div>

Hi all,

A new user to Ignition, dba, and scripting but learning. I am using PostgreSQL as my database. I have successfully created a simple database editor as described in the Ignition user manual 8.0. This editor works great!

When I add data to the table the “id” column is automatically updated and is an index.

Now I have created a new table and cant get the “id” column to update automatically.

I just get a null value in the table.

I am testing it in the Named Query editor.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/7/67a1dc7f6f382f94536a8483870fd5f356a8a113.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/d/0d52a6afc084555a7482c1869d88593fe8ebb1ef.png)

I had the id column as the primary key and could not get the insert statement to work without explicitly defining every column.

What am I missing? How do I make the id column automatic?

Thanks for the help,

Steven

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 6, 2020, 3:53pm UTC](https://forum.inductiveautomation.com/t/postgresql-queries-and-primary-keys/39425/2 "2020-10-06T15:53:47Z")

</div>

When you create the table, declare the id column as type `serial` instead of any integer type… that triggers PostgreSQL’s automatic sequence creation and attachment as the default value for that column.

---

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [October 6, 2020, 5:11pm UTC](https://forum.inductiveautomation.com/t/postgresql-queries-and-primary-keys/39425/3 "2020-10-06T17:11:12Z")

</div>

@pturmel,

That works. However, I have a database that works where the id is INTEGER. I would like to know why it works and this one didn’t.

Either way, that works and gets me back on track. I will set all indexes to serial in the future to avoid any issues.

Thanks for the help!!

Steven

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 6, 2020, 7:12pm UTC](https://forum.inductiveautomation.com/t/postgresql-queries-and-primary-keys/39425/4 "2020-10-06T19:12:37Z")

</div>

> [@steven.cox](#):
>
> However, I have a database that works where the id is INTEGER. I would like to know why it works and this one didn’t.

But that's what `serial` does. It creates an [integer column](https://www.postgresql.org/docs/10/datatype-numeric.html) and hooks up a [SEQUENCE](https://www.postgresql.org/docs/10/sql-createsequence.html) to supply the auto-incrementing values.

You can manually create a sequence and attach it to an existing integer column.
