将相同值插入2列的简便方法 [英] easy way to insert same value into 2 columns
问题描述
您好,
最简单的方法是将相同的值插入同一张桌子的两列
吗?
我的桌子看起来像这样:
Spalte | Typ |属性
-------- + --------- + ----------------------
id |整数|默认nextval(''public.zeit_id_seq'':: text)
pos_id |整数|默认xxx
为xxx我想要与id相同的值自动插入
问候
塞巴斯蒂安
---------------------------(播出结束)------- --------------------
提示9:如果您的
$ b,计划员将无视您选择索引扫描的愿望$ b加入列的数据类型不匹配
Hello,
whats the most simple way to insert the same value into 2 colums of
the same table?
My table is looking like this:
Spalte | Typ | Attribute
--------+---------+----------------------
id | integer | default nextval (''public.zeit_id_seq''::text)
pos_id | integer | default xxx
for the xxx i want the same value than id be inserted automatically
Regards
Sebastian
---------------------------(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
推荐答案
针对您的具体问题,我不知道答案。
对于这个特殊情况你可以使用:
创建表your_table(
id整数默认nextval(''' public.zeit_id_seq'':: text),
pos_id整数默认currval(''public.zeit_id_seq'':: text),
...
);
只要你使用不指定id的插入物就可以正常工作
如果没有指定pos_id(否则currval会给你一个
的错误,因为它不能是c没有下一个被叫的alled。
HTH,
Csaba。
On Thu,2003-10-在11点40分,Sebastian Boeck写道:
For your specific question I don''t know the answer.
For this particular case you could use:
create table your_table (
id integer default nextval (''public.zeit_id_seq''::text),
pos_id integer default currval (''public.zeit_id_seq''::text),
...
);
That would work fine as long as you use inserts which don''t specify id
if pos_id is not specified (otherwise the currval will throw you an
error cause it cannot be called without nextval being called).
HTH,
Csaba.
On Thu, 2003-10-16 at 11:40, Sebastian Boeck wrote:
你好,
最简单的方法是将同一个值插入同一个表的2个列中吗?
我的桌子看起来像这样:
Spalte | Typ |属性
-------- + --------- + ----------------------
id |整数| default nextval(''public.zeit_id_seq'':: text)
pos_id |整数|默认xxx
对于xxx我想要与id相同的值自动插入
问候
塞巴斯蒂安
- --------------------------(广播结束)------------------- --------
提示9:如果您的
加入列的数据类型不匹配,规划人员将忽略您选择索引扫描的愿望
Hello,
whats the most simple way to insert the same value into 2 colums of
the same table?
My table is looking like this:
Spalte | Typ | Attribute
--------+---------+----------------------
id | integer | default nextval (''public.zeit_id_seq''::text)
pos_id | integer | default xxx
for the xxx i want the same value than id be inserted automatically
Regards
Sebastian
---------------------------(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
---------------------------(广播结束)----------- ----------------
提示2:您可以使用取消注册命令一次性取消所有列表
(发送& ;取消注册YourEmailAddressHere以 ma*******@postgresql.org )
>
Csaba Nagy写道:
Csaba Nagy wrote:
针对您的具体问题,我不知道答案。
对于这个特殊情况你可以使用:
创建表your_table(
id整数默认nextval(''public.zeit_id_seq'':: text),
p os_id整数默认currval(''public.zeit_id_seq'':: text),
...
);
只要你使用插入的东西就可以正常工作如果没有指定pos_id,则指定id
(否则currval会引发一个
错误,因为如果没有调用nextval就无法调用它。)
HTH,
Csaba。
For your specific question I don''t know the answer.
For this particular case you could use:
create table your_table (
id integer default nextval (''public.zeit_id_seq''::text),
pos_id integer default currval (''public.zeit_id_seq''::text),
...
);
That would work fine as long as you use inserts which don''t specify id
if pos_id is not specified (otherwise the currval will throw you an
error cause it cannot be called without nextval being called).
HTH,
Csaba.
非常感谢,但是可以节省使用吗?
我总是得到相同的价值,即使其他插页正在改变
序列> public.zeit_id_seq<只是在同一时间?
问候
塞巴斯蒂安
---------- -----------------(广播结束)---------------------------
提示7:别忘了增加你的免费空间地图设置
Thanks a lot, but is it save to use?
Do i always get the same value, even if an other insert is changing
the sequence >public.zeit_id_seq< just at the same time?
Regards
Sebastian
---------------------------(end of broadcast)---------------------------
TIP 7: don''t forget to increase your free space map settings
Sebastian Boeck写道:
Sebastian Boeck wrote:
我总是得到相同的值,即使其他插入正在改变
序列> public.zeit_id_seq<只是在同一时间?
Thanks a lot, but is it save to use?
Do i always get the same value, even if an other insert is changing the
sequence >public.zeit_id_seq< just at the same time?
您可以编写一个插入前触发器,在此处检索序列值一次,并为两个字段设置
。这样它将确保两个字段都相同
值。
HTH
Shridhar
---------------------------(播出结束)------------ ---------------
提示7:别忘了增加免费空间地图设置
You can write a before insert trigger where you retrieve sequence value once and
set for two fields. That way it will ensure that both the fields would get same
value.
HTH
Shridhar
---------------------------(end of broadcast)---------------------------
TIP 7: don''t forget to increase your free space map settings
这篇关于将相同值插入2列的简便方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!