与PostgreSQL 8.3相同的nextval序列

时间:2013-05-23 13:35:17

标签: php postgresql cakephp

设置

  • CakePHP 2.3.5
  • PostgreSQL 8.3
  • Apache 2.2
  • PHP 5.3.8
  • Windows 7 Ultimate x64

问题

当我执行此查询2次时,返回相同的值?

$sql = "select nextval('auth_num_seq') as nextval";
$nextval = $this->query($sql);

return $nextval[0][0]['nextval'];

为什么?

我也尝试过,但不起作用?

$sql = "select setval('auth_num_seq', nextval('auth_num_seq') + 1, false)";
$setval = $this->query($sql);

$sql = "select nextval('auth_num_seq') as nextval";
$nextval = $this->query($sql);

return $nextval[0][0]['nextval'];

1 个答案:

答案 0 :(得分:1)

我在此链接中找到了解决方案:http://cakephp.1045679.n5.nabble.com/how-to-disable-query-caching-td1297496.html

感谢 AD7six !!

我需要这样做:$this->query('some sql', false);。将第二个参数设置为 false