`
ggsonic
  • 浏览: 272342 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

get next auto_id sequence

阅读更多
简单的说,目标就是获取数据库表中的下一个auto_id sequence.
先看了这篇文章: http://blog.jamiedoris.com/geek/560/。在MySQL中使用
 "SHOW TABLE STATUS LIKE '$tablename'";

我用的PostgreSQL8, Google了下,找到了一个pg下类似的方法:
select currval(pg_get_serial_sequence(tablename, id_seq))

但出现错误:currval of sequence is not yet defined in this session
currval只能在执行 NEXTVAL 后执行。解决方法是使用
select last_value from seq
但最后又有一个小问题,新建立的数据库,返回的last_value是1;而添加成功一个后,第二个返回的也是1,添加不成功。用了比较土的方法规避了下。

分享到:
评论

相关推荐

    java通过Mysql实现类似oracle序列功能序列.rar

    在MySQL中,定义一个存储过程如`GET_NEXT_SEQUENCE`,它会查询`sequence`表的最新`id`并增加1。 5. **Java调用存储过程**: - 使用`CallableStatement`对象,你可以调用MySQL的存储过程。设置参数和获取结果集,...

    java生成数据库表序列号

    对于不支持序列的数据库,如MySQL,可以通过设置主键的`auto_increment`属性,然后执行`INSERT`语句来自动获取新生成的ID。 在实际项目中,我们可能会使用ORM框架如Hibernate或MyBatis来简化数据库操作。例如,在...

    ImageMagick图片批量处理

    -delay value display the next image after pausing -density geometry horizontal and vertical density of the image -depth value image depth -direction type render text right-to-left or left-to-right...

    C++MFC教程

    例如当菜单转中之后会有WM_COMMAND消息发送,WPARAM的高字中(HIWORD(wParam))是命令的ID号,对菜单来讲就是菜单ID。当然用户也可以定义自己的消息名称,也可以利用自定义消息来发送通知和传送数据。 2、谁将收到...

    微软内部资料-SQL性能优化5

    In any index, whether clustered or nonclustered, the leaf level contains every key value, in key sequence. In SQL Server 2000, the sequence can be either ascending or descending. The sysindexes table ...

    iOS-2048-master

    tap "Auto Run" to run AI automatically. Check it out in the `AI` branch. You can also check out [this demo video on YouTube](https://www.youtube.com/watch?v=GF0ANNPpF8E). Thanks to [ov3y]...

    python3.6.5参考手册 chm

    index modules | next | Python » 3.6.5 Documentation » Python Documentation contents What’s New in Python What’s New In Python 3.6 Summary – Release highlights New Features PEP 498: Formatted ...

    2009 达内Unix学习笔记

    id -a root 显示用户所在组的所有组名(如root用户,是所有组的组员) df 查看文件系统,查看数据区 用法 df [-F FSType] [-abeghklntVvZ] [-o FSType 特定选项] [目录 | 块设备 | 资源] df -k 以kbytes显示文件...

Global site tag (gtag.js) - Google Analytics