如何通过 pgAdmin 将序列设置为默认值?

发布于 2024-08-22 05:46:15 字数 251 浏览 4 评论 0原文

我有一个 posgreSQL 数据库,我正在使用 pgAdmin III 来处理它。我创建了一个名为 PrimaryKeySequence 的序列。

现在我想使用这个序列作为表中主键字段的默认值。我尝试插入

nextval('primaryKeySequence');

pgAdmin 中的默认值文本字段。当我单击“确定”按钮时,会出现一条错误消息,提示该序列不存在。

正确的做法是什么?

I have a posgreSQL database and I am using pgAdmin III to work with it.I created a sequence called primaryKeySequence.

Now I want to use this sequence as the default value for a primary key field in a table. I tried to insert

nextval('primaryKeySequence');

into the default value textfield in pgAdmin. When I click the 'OK'-button an error message comes up and says, that the sequence does not exist.

What is the right way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谈场末日恋爱 2024-08-29 05:46:15

知道了。看看这里: http://pgadmin.org/docs/1.4/pg /functions-sequence.html 序列名称必须像这样 nextval('"primaryKeySequence"') 一样加引号,因为它不是小写的

Got it. Have a look here: http://pgadmin.org/docs/1.4/pg/functions-sequence.html The sequence name has to be quoted like this nextval('"primaryKeySequence"') because it is not lowercase

舞袖。长 2024-08-29 05:46:15

PostgreSQL 将会把标识符小写,除非你“”。所以尝试:

nextval('primarykeysequence')

另外,你做错了。请改用 Serial/BigSerial。

PostgreSQL is going to lowercase the identifier unless you "". So try:

nextval('primarykeysequence')

Also, you are doing it wrong. Use Serial/BigSerial instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文