如何使用 PostgreSQL 在 DBeaver 上创建自动递增/SERIAL id 列? [英] How to create auto incrementing / SERIAL id column's on DBeaver using PostgreSQL?

查看:424
本文介绍了如何使用 PostgreSQL 在 DBeaver 上创建自动递增/SERIAL id 列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PostgreSQL 和 DBeaver(社区版 5.1.6 版)的新用户,并且正在寻找一种方法来通过 DBeaver GUI 在表中创建自动递增的 ID 列.

从我的研究中我可以看出:

  1. 您可以使用 SQL 轻松地进行设置,例如.id 序列号 NOT_NULL

  2. 根本问题是没有串行数据类型"这样的东西,SERIAL 等同于 nextval('table_name_id_seq').

  3. 当我在 SQL 中使用 SERIAL 命令创建表时,生成的 id 列在默认"属性中具有 nextval('exampletable_id_seq'::regclass') 值.

例如,我尝试在新表中 DBeaver 列的默认"属性中手动输入 nextval() 命令.nextval('mytable_id_seq') 带和不带 '::regclass;.但是这不起作用.

我很欣赏在 SQL 中执行此操作会更容易,并且之前有一个问题在:

由于 PostgreSQL 的工作方式,'Serial' 类型是一种伪类型,它允许使用一系列数字 (

感谢您对熟悉 PostgreSQL 和/DBeaver 的任何人来说,这是一个非常明显的答案,感谢您的理解 :)

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:

  1. You can set this up easily using SQL eg. id SERIAL NOT_NULL

  2. 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').

  3. 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:

  1. Is there a functionality for DBeaver to add auto incrementing id's through the GUI?

  2. If so, what would be the steps to do this.

Thanks very much everyone!

解决方案

After reviewing the very helpful comments to my question above, I have realised 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:

  1. Yes there is a way to auto increment directly through the DBeaver GUI.

  2. This can be done by setting up a 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 primary key through constraints.

Screenshot attached below:

Due to the way PostgreSQL works, the 'Serial' type is a pseudotype which 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 :)

这篇关于如何使用 PostgreSQL 在 DBeaver 上创建自动递增/SERIAL id 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆