本文介绍了SQL-question:返回插入querry的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-----开始PGP签名消息-----

哈希:SHA1





我建立一个用户数据库,其中包含许多表格,用于保存

地址,电话号码等数据,这些数据由我保留的表格引用

单个用户。我的问题是,如何获取新的

插入地址的Id值以将其存储在引用用户表中:


( a)INSERT INTO地址值(....);


(b)INSERT INTO用户VALUES(名称,......,地址,......);


其中地址应该保留Adress表中Id的值。

必须要做一个

SELECT id FROM FROM WHERE oid = oid_returned_by_insert(a)

或类似之后做插入(a)以获得正确的id

值,或者有更好的方法来做到这一点。 />

我用DBD / DBI用Perl编写我的应用程序

提前致谢,


Andreas Fromm


-----开始PGP SIGNATURE -----

版本:GnuPG v1.2.1(GNU / Linux)

评论:将GnuPG与Mozilla一起使用 -


iD8DBQE / rhcdPkvkZVZzNY0RApm DAJ4k4MY / zKvH2862MuHSIjDtsmIs3QCfRzaR

0zDc1bIQAOMpLurvRZ2V8JY =

= kgaA

----- END PGP SIGNATURE -----

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

提示9:如果您的

加入列的数据类型,计划程序将忽略您选择索引扫描的愿望不匹配

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Im building an user database with many tables keeping the data for the
Address, Phone numbers, etc which are referenced by a table where I keep
the single users. My question is, how do I get the "Id"-value of a newly
inserted address to store it in the referencing user table:

(a) INSERT INTO address VALUES (....);

(b) INSERT INTO users VALUES ( name, ... , address , ... );

where address should hold the value of the Id from the Adress table.
Do have to do an
SELECT id FROM address WHERE oid = oid_returned_by_insert(a)
or something like that after doing the insert(a) to get the correct id
value, or is there a better way to do this.

Im writing my app in Perl with DBD/DBI
Thanks in advance,

Andreas Fromm

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/rhcdPkvkZVZzNY0RApmDAJ4k4MY/zKvH2862MuHSIjDtsmIs3QCfRzaR
0zDc1bIQAOMpLurvRZ2V8JY=
=kgaA
-----END PGP SIGNATURE-----
---------------------------(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

推荐答案




----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.0.6(GNU / Linux)

评论:有关信息,请参阅


iD8DBQE / riFbY5Twig3Ge + YRArk / AKDU1nU6pzTtFVYjWXwsV0Dd2VtYagCgiBm4

SCBl2fXmByxYY8 + wHZ965mQ =

= rQMo

-----结束PGP签名-----



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE/riFbY5Twig3Ge+YRArk/AKDU1nU6pzTtFVYjWXwsV0Dd2VtYagCgiBm4
SCBl2fXmByxYY8+wHZ965mQ=
=rQMo
-----END PGP SIGNATURE-----




...试试吧。谢谢


Andreas Fromm


----- BEGIN PGP SIGNATURE -----

版本: GnuPG v1.2.1(GNU / Linux)

评论:在Mozilla中使用GnuPG -


iD8DBQE / rkMwPkvkZVZzNY0RAnajAJ0ePCTi / UODhGAxO​​s5NuptZAT0tUgCgpNAz

Oqh8rM934O3SRRzv4Mh9S4I =

= E71z

----- END PGP SIGNATURE -----

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

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

(发送取消注册YourEmailAddressHere到)


...going to try it. Thanks

Andreas Fromm

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/rkMwPkvkZVZzNY0RAnajAJ0ePCTi/UODhGAxOs5NuptZAT0tUgCgpNAz
Oqh8rM934O3SRRzv4Mh9S4I=
=E71z
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)





如果其他人在我获得currval之前插入了另一个地址怎么办?

我不幸运,对吗?


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

提示6:你有没有?搜索了我们的列表档案?





What if someone else inserts another address before I get the currval?
I''m out of luck then, right?

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


这篇关于SQL-question:返回插入querry的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-06 12:53