单排表? [英] Single Row Table?

查看:66
本文介绍了单排表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一张桌子应该只包含一行。确实

没有定义任何主键。

所以,基本上,当在该表中发生新的插入时,我想

它如果

表中已经存在一行,则(插入)失败。

我该怎么做?我可以添加任何约束吗?或者我需要写一个

单独的触发器吗?


谢谢和问候,


Yateen V. Joshi


Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?

Thanks and regards,

Yateen V. Joshi


推荐答案

2004年8月27日星期五13:32:07 + 0530, />
Yateen Joshi< yj **** @ starentnetworks.com>写道:
On Fri, Aug 27, 2004 at 13:32:07 +0530,
Yateen Joshi <yj****@starentnetworks.com> wrote:


我有一个表应该只包含一行。它确实没有定义任何主键。
所以,基本上,当在该表中发生新插入时,如果已经有一行,我希望它(插入)失败存在于
表中。
我该怎么做?我可以添加任何约束吗?或者我是否需要为它编写单独的触发器?
Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?




强制执行此操作的一种简单方法是添加主键和约束

强制主键成为特定值。


--------------------- ------(播出结束)---------------------------

提示2:你可以使用取消注册命令一次性取消所有列表

(发送取消注册YourEmailAddressHere到 ma * ******@postgresql.org



A simple way to force this is to add a primary key and a constraint
that forces the primary key to be a particular value.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)


On Sun,2004-08-29 15:30,Bruno Wolff III写道:
On Sun, 2004-08-29 at 15:30, Bruno Wolff III wrote:
周五,2004年8月27日13:32:07 +0530,
Yateen Joshi< yj **** @ starentnetworks.com>写道:
On Fri, Aug 27, 2004 at 13:32:07 +0530,
Yateen Joshi <yj****@starentnetworks.com> wrote:


我有一个表应该只包含一行。它确实没有定义任何主键。
所以,基本上,当在该表中发生新插入时,如果已经有一行,我希望它(插入)失败存在于
表中。
我该怎么做?我可以添加任何约束吗?或者我是否需要为它编写一个单独的触发器?
Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?



强制执行此操作的一种简单方法是添加主键和约束
主键是一个特定的值。



A simple way to force this is to add a primary key and a constraint
that forces the primary key to be a particular value.




是否合理/可能添加一个检查约束,例如

select count(*)来自表< = 1?

---------------------------(广播结束)--- ------------------------

提示9:如果您的
加入列的数据类型不匹配



Is it reasonable / possible to add a check constraint something like
select count(*) from table <=1?
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column''s datatypes do not match


On Sun,2004年8月29日15:38:45 -0600,

Scott Marlowe< sm ****** @ qwest.net>写道:
On Sun, Aug 29, 2004 at 15:38:45 -0600,
Scott Marlowe <sm******@qwest.net> wrote:
On Sun,2004-08-29 15:30,Bruno Wolff III写道:
On Sun, 2004-08-29 at 15:30, Bruno Wolff III wrote:
周五,2004年8月27日13:32:07 + 0530,
Yateen Joshi< yj **** @ starentnetworks.com>写道:
On Fri, Aug 27, 2004 at 13:32:07 +0530,
Yateen Joshi <yj****@starentnetworks.com> wrote:


我有一个表应该只包含一行。它确实没有定义任何主键。
所以,基本上,当在该表中发生新插入时,如果已经有一行,我希望它(插入)失败存在于
表中。
我该怎么做?我可以添加任何约束吗?或者我是否需要为它编写一个单独的触发器?
Hi,

I have got a table which is supposed to contain only one row. It does
not have any primary keys defined.
So, essentially, when a new insert happens in that table, I would like
it (the insert) to fail if there is already a row existing in that
table.
How can I do that? Can I add any constraints? Or do I need to write a
separate trigger for the same?



强制执行此操作的一种简单方法是添加主键和约束
主键是一个特定的值。



A simple way to force this is to add a primary key and a constraint
that forces the primary key to be a particular value.



是否合理/可能添加一个检查约束,例如
select table(*)from table< = 1?



Is it reasonable / possible to add a check constraint something like
select count(*) from table <=1?




应该可以使用after触发器来实现,但是有一点

设置更多的工作。只要桌子被吸尘,无论哪种方式

可能都相当快。


--------------- ------------(广播结束)---------------------------

提示2:您可以使用取消注册命令一次性取消所有列表

(发送取消注册YourEmailAddressHere到 ma ******* @ postgresql.org



It should be possible to do that with an after trigger, but it is a bit
more work to set up. As long as the table gets vacuumed, either way
is probably reasonably fast.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)


这篇关于单排表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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