2

I´m a new user (noob) of Dbeaver (community edition) and PostgreSQL, and I was having big trouble in defining an auto-incremented Primary Key in any table, so I would like to know how to be able to define an auto-incremented primary key using DBeaver, answers must no include these trials:

  1. Defining the primary key as serial (DBeaver will change it automatically to int2-4-8 even when defining the Primary Key as not null).
  2. Defining a new sequence in DBeaver (the best way to define a new sequence is throw pgAdmin4 and you may not be that successful to assign it to the table's Primary Key if your a noob just like I´m either in DBeaver or in pgAdmin4).
Nader Belal
  • 157
  • 3
  • 10
  • serial is int2-4-8, plus sequence. why not using SQL statements?.. – Vao Tsun Dec 11 '17 at 12:17
  • There is no real data type `serial`. It's a short hand for an integer column with a sequence as the default value. https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL So the best way to create a table with a serial data type is to define it as a serial. Apparently DBeaver displays the table the same way as `psql`: https://imgur.com/a/m8TI4 –  Dec 11 '17 at 12:19
  • @VaoTsun, int2-4-8, I meant (int2 - int4 - int8), and what should be that SQL statement ?? – Nader Belal Dec 11 '17 at 13:17
  • 1
    My problem with **DBeaver** is that I can't generate a sequence from with in the program, nor define a serial type as I can do in **pgAdmin4**, and even when I manage to bypass all these problems, when ever I try to add a new record from within **DBeaver**, it doesn't generate an automatic primary key number, it gives me an error message that the primary key have a null value, when it it was defined as Not Null – Nader Belal Dec 11 '17 at 13:21
  • please update your post with existing table DDL and clearly define what you try to do and what is not working – Vao Tsun Dec 11 '17 at 13:27

1 Answers1

2

I also could not find this in the DBeaver GUI. You could issue the following sql query against your table:

ALTER TABLE public."Customer"
    ALTER COLUMN customer_id ADD GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 );
Mohana B C
  • 5,021
  • 1
  • 9
  • 28
selswick
  • 21
  • 3