I am a new user for both PostgreSQL and DBeaver (Community edition ver. 5.1.6) and was looking for a way to create an auto incrementing ID column in a table through the DBeaver GUI.
From my research I can see that:
You can set this up easily using SQL eg. id SERIAL NOT_NULL
The underlying problem is that there is no such thing as a 'Serial data type', and that SERIAL equates to nextval('table_name_id_seq').
When I create a table using the SERIAL command in SQL the resulting id column has a nextval('exampletable_id_seq'::regclass') value in the 'Default' attribute.
I have attempted to manually input the nextval() command within the 'Default' attribute for the column in DBeaver in a new table, for example. nextval('mytable_id_seq') with and without the '::regclass;. However this is not working.
I appreciate that doing this in SQL would be easier, and that there is a previously asked question at: Problems de Serial data type in DBeaver & PostgreSQL.
However, I could not find a satisfactory answer and the option of being able to do this through the GUI would be useful, especially if other setup is being done through the DBeaver GUI.
Specifically, my question is:
Is there a functionality for DBeaver to add auto incrementing id's through the GUI?
If so, what would be the steps to do this.
After reviewing the very helpful comments to my question above, I have realized that the question was asked due to my lack of experience with DBeaver.
For completeness I have set out the answer to my question below:
Yes there is a way to auto-increment directly through the DBeaver GUI.
This can be done by setting up an id variable when a table is created by setting a column with a type of serial and "not null" ticked, then setting the id as a primary key through constraints.
Screenshot attached below:
Due to the way PostgreSQL works, the 'Serial' type is a pseudotype that allows a sequence of numbers to be used (http://www.postgresqltutorial.com/postgresql-serial/).
So, in DBeaver, once you set up the tables this will be displayed as the following rather than with a 'serial' type:
I appreciate that this is a very obvious answer to anyone who is familiar with PostgreSQL and/ DBeaver, thank you for your understanding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With