Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL No Auto Increment function?

I have a test application coded in Java for creating an indexed and non indexed table in a MySQL, PostgreSQL, Oracle and Firebird database (Amongst other things).

Is it simply a case that PostgreSQL doesnt allow the auto increment feature? If not, what is the normal procedure for having an indexed coloumn?

Thanks in advance

like image 554
Simon Cottrill Avatar asked Jun 28 '26 08:06

Simon Cottrill


1 Answers

You may use SERIAL in PostgreSQL to generate auto increment field,

For eg:-

CREATE TABLE user (
userid SERIAL PRIMARY KEY,
username VARCHAR(16) UNIQUE NOT NULL
)

This will create userid as auto-increment primary key indexed. If you don't want this as primary key, just remove PRIMARY KEY.

like image 166
sojin Avatar answered Jul 01 '26 06:07

sojin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!