首页 > 数据库技术 > 详细

postgresql实现插入数据返回当前的主键ID

时间:2017-03-07 19:17:29      阅读:1077      评论:0      收藏:0      [点我收藏+]
  <insert id="addUser" parameterType="com.liupan.user">
         <selectKey keyProperty="id" resultType="java.lang.Integer" order="AFTER">
             select currval(‘user_user_id_seq‘) as id
         </selectKey>
         insert into USER(USER_NAME,PASSWORD,CREATE_TIME) 
         values(#{userId},#{password},#{createTime,typeHandler=dateTimeTypeHandler})
   </insert>

除了currval()函数外,还有nextval()函数,但是nextval()函数会导致postgresql的主键加1,所以不能用在这种情况下

postgresql实现插入数据返回当前的主键ID

原文:http://www.cnblogs.com/lwmp/p/6516240.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!