GetLastInsertID? [英] GetLastInsertID ?

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

问题描述

祝所有pgsql粉丝新年快乐!


对于这个微不足道的问题我很抱歉,但我无法在

档案中找到答案:


我在id列的表中使用SERIAL类型来自动增加

它们。有没有办法得到

表格中最后一个插入的id就像我们用MySQL做的那样使用

GetLastInsertID?


我的需要是在插入后立即取回新的id。如果我在插入之前将其称为

,那么nextval可以

回应这个需求吗?


非常感谢你。

$ b $bStéphane


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

提示3:如果通过Usenet发布/阅读,请发送适当的

subscribe-nomail命令到 ma*******@postgresql.org 这样你的

消息就可以干净利落地进入邮件列表

Happy new year to all pgsql fans !

Sorry for this trivial question but I couldn''t find an answer in the
archives :

I use SERIAL type in tables for id columns in order to auto increment
them. Is there a way to get
the last inserted id in the table like we do with MySQL using the
GetLastInsertID ?

My need is to get back the new id just after inserting. Is nextval can
respond to this need if I call it
just before inserting ?

Thank you very much.

Stéphane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

推荐答案

On 2004年1月1日星期四,Stephane Pinel写道:
On Thu, 1 Jan 2004, Stephane Pinel wrote:
表中最后插入的id就像我们用MySQL使用
GetLastInsertID一样?

我需要在插入后立即取回新的id。
the last inserted id in the table like we do with MySQL using the
GetLastInsertID ?

My need is to get back the new id just after inserting.




插入后使用currval()。

http://www.postgresql.org/docs/curre...-sequence.html


-

/ Dennis

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

提示8:解释分析是你的朋友



Use currval() after you have inserted.

http://www.postgresql.org/docs/curre...-sequence.html

--
/Dennis
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


如果在插入之前使用nextval,则应使用插入值

本身。之后你可以使用currval来获得刚刚插入的值。


我很惊讶你在档案馆里找不到这个,它几乎被问到了/>
每周。


这也是FAQ的问题4.15.2:

http://www.postgresql.org/docs/faqs/FAQ.html#4.15。 2


希望这会有所帮助,


2004年1月1日星期四04:10:56 + 0100,Stephane Pinel写道:
If you use nextval before the insert, you should use the value in the insert
itself. Afterwards you can use currval to get the just inserted value.

I''m surprised you can''t find this in the archives, it''s asked on an almost
weekly basis.

It''s also question 4.15.2 of the FAQ:

http://www.postgresql.org/docs/faqs/FAQ.html#4.15.2

Hope this helps,

On Thu, Jan 01, 2004 at 04:10:56PM +0100, Stephane Pinel wrote:
祝所有pgsql粉丝新年快乐!

抱歉这个琐碎的问题,但我在
档案中找不到答案:

我在id列的表中使用SERIAL类型来自动增加它们。有没有办法在表格中使用
GetLastInsertID来获取表格中最后插入的ID?

我需要的是在插入后立即取回新的ID 。如果我在插入之前将其称为
,nextval可以回应这个需求吗?

非常感谢。

Stéphane
< br ----> ---------------------------(播出结束)--------------- ------------
提示3:如果通过Usenet发布/阅读,请发送适当的
subscribe-nomail命令到 ma ******* @ postgresql.org ,以便您的
消息可以干净地通过邮件列表


-

Martijn van Oosterhout< kl ***** @ svana.org> http://svana.org/kleptog/ (......已经离开了在任何地方,即使是开发商也几乎无法使用,大约20%完成。很好。最后的80%通常需要20%的时间,对吧?) - Anthony Towns,debian- devel-announce
Happy new year to all pgsql fans !

Sorry for this trivial question but I couldn''t find an answer in the
archives :

I use SERIAL type in tables for id columns in order to auto increment
them. Is there a way to get
the last inserted id in the table like we do with MySQL using the
GetLastInsertID ?

My need is to get back the new id just after inserting. Is nextval can
respond to this need if I call it
just before inserting ?

Thank you very much.

Stéphane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ (... have gone from d-i being barely usable even by its developers
anywhere, to being about 20% done. Sweet. And the last 80% usually takes
20% of the time, too, right?) -- Anthony Towns, debian-devel-announce




-----开始PGP签名-----

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

评论:有关信息,请参阅 http://www.gnupg.org


iD8DBQE / 9EdzY5Twig3Ge + YRAuG6AJ4iMN3RQW0pjFzDNxmjyqxCbGr3xA Cg1tm0

o7j0V61Oi1uCan0LzRxn3RY =

= O3tr

- ----结束PGP SIGNATURE -----



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

iD8DBQE/9EdzY5Twig3Ge+YRAuG6AJ4iMN3RQW0pjFzDNxmjyqxCbGr3xA Cg1tm0
o7j0V61Oi1uCan0LzRxn3RY=
=O3tr
-----END PGP SIGNATURE-----


插入


后应使用curval这可以一步完成


插入foo(c1,c2,...)值(v1,v2 ......);选择curval(序列

);


Dave

On Thu,2004-01-01 at 10:10,Stephane Pinel写道:
You should use curval after inserting

and this can be done in one step

insert into foo (c1,c2,...) values ( v1, v2...); select curval( sequence
);

Dave
On Thu, 2004-01-01 at 10:10, Stephane Pinel wrote:
祝所有pgsql粉丝新年快乐!

抱歉这个琐碎的问题,但我无法在
档案中找到答案:

我在表格中使用SERIAL类型作为id列,以便自动增加它们。有没有办法在表格中使用
GetLastInsertID来获取表格中最后插入的ID?

我需要的是在插入后立即取回新的ID 。如果我在插入之前将其称为
,nextval可以回应这个需求吗?

非常感谢。

Stéphane
< br ----> ---------------------------(播出结束)--------------- ------------
提示3:如果通过Usenet发布/阅读,请发送适当的
subscribe-nomail命令到 ma ******* @ postgresql.org ,以便您的
消息可以干净地通过邮件列表
Happy new year to all pgsql fans !

Sorry for this trivial question but I couldn''t find an answer in the
archives :

I use SERIAL type in tables for id columns in order to auto increment
them. Is there a way to get
the last inserted id in the table like we do with MySQL using the
GetLastInsertID ?

My need is to get back the new id just after inserting. Is nextval can
respond to this need if I call it
just before inserting ?

Thank you very much.

Stéphane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly



-

Dave Cramer

519 939 0336

ICQ#1467551

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

提示6:您是否搜索了我们的列表档案?

http://archives.postgresql.org


--
Dave Cramer
519 939 0336
ICQ # 1467551
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


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

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