gpt4 book ai didi

ruby - 如何从 PgSQL DB 获取时间

转载 作者:数据小太阳 更新时间:2023-10-29 07:55:16 24 4
gpt4 key购买 nike

我正在尝试使用 pg gem 获取查询的时间。我看到了文档,但没有找到任何东西。我想知道是否有类似 query.time 的东西。

我在 ~/.psqlrc 中添加了 \timing,因此该命令默认处于事件状态。如果我在 Postgres 控制台中编写查询,则时间处于事件状态。

这是代码:

conn = PGconn.open(:dbname => 'my_db') 
query=conn.exec('SELECT * from some_table')
puts query.num_tuples -> this work
puts query.time -> undefined method

我需要测量 Postgres 本身的时间,我不能使用 Ruby 的 Time 类。

最佳答案

试试这个,因为它应该会返回时间。

puts conn.exec("EXPLAIN ANALYZE SELECT * FROM some_table").values

关于ruby - 如何从 PgSQL DB 获取时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35905793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com