postgresql nextval 关于序列的问题

发布于 2024-08-19 22:06:01 字数 309 浏览 2 评论 0原文

我正在尝试在 PHP 中使用 postgresql 'nextval'。如何填写第三行中的括号以便将 TXN_ID 替换为 nextval('schemadb.audit_txn_seq') 的值?

$DB->query("SELECT nextval('schemadb.audit_txn_seq')");
$DB->query('SET CONSTRAINTS ALL DEFERRED');
$DB->query('SELECT schemadb.undo_transaction(TXN_ID)');

谢谢!

I am trying to work with postgresql 'nextval' in PHP. How can I fill in the parenthesis in the third line in order to replace TXN_ID with the value of nextval('schemadb.audit_txn_seq')?

$DB->query("SELECT nextval('schemadb.audit_txn_seq')");
$DB->query('SET CONSTRAINTS ALL DEFERRED');
$DB->query('SELECT schemadb.undo_transaction(TXN_ID)');

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍白女子 2024-08-26 22:06:01

您没有告诉我们什么是 $DB 变量。我猜你正在使用 PDO。

“是否有办法将查询结果存储到 php 变量中”这个问题是一种初学者问题,在 手册

您必须明白,(从 PHP 的角度来看)

SELECT nextval('schemadb.audit_txn_seq')

SELECT xcolumn FROM xtable LIMIT 1

之间没有区别。如果您想从任何查询中获取数据值,您总是以相同的标准方式执行:

  1. queryexecute
  2. fetch
  3. 希望

有帮助。

You did not tell us what is $DB variable. I guess you are using PDO.

The question "Is there anyway to store the result of query into php variable" is kind of beginner question, and is easilly answered in the manual.

You must understand, that (from PHP's point of view) there is no difference between

SELECT nextval('schemadb.audit_txn_seq')

and

SELECT xcolumn FROM xtable LIMIT 1

If you want to fetch data values from ANY query, you do it always the same, standard way:

  1. query
  2. execute
  3. fetch

Hope that helps.

浅语花开 2024-08-26 22:06:01

尝试:

$DB->query("SELECT nextval('schemadb.audit_txn_seq')");
$DB->query('SET CONSTRAINTS ALL DEFERRED');
$DB->query("SELECT schemadb.undo_transaction( currval('schemadb.audit_txn_seq') )");

Try:

$DB->query("SELECT nextval('schemadb.audit_txn_seq')");
$DB->query('SET CONSTRAINTS ALL DEFERRED');
$DB->query("SELECT schemadb.undo_transaction( currval('schemadb.audit_txn_seq') )");
゛清羽墨安 2024-08-26 22:06:01

我不确定与 SET CONSTRAINTS ALL DEFERRED 的交互,但是您是否尝试过这样做:

SELECT schemadb.undo_transaction(nextval('schemadb.audit_txn_seq'))

现在的问题是“undo_transaction”返回什么?如果成功完成后返回交易 ID,那么您就可以开始了!

I'm not sure about the interaction with SET CONSTRAINTS ALL DEFERRED, but have you tried doing this:

SELECT schemadb.undo_transaction(nextval('schemadb.audit_txn_seq'))

The question is now what does "undo_transaction" return? If it returns the transaction ID upon successful completion, then you're good to go!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文