I'm attempting to get the timing of a query using the pg gem. I saw the documentation, but I did not find anything. I want to know if there is something like query.time.
I added \timing to ~/.psqlrc, so the command is active by default. If I write the query in the Postgres console the time is active.
This is the code:
conn = PGconn.open(:dbname => 'my_db')
query=conn.exec('SELECT * from some_table')
puts query.num_tuples -> this work
puts query.time -> undefined method
I need to measure the time of Postgres itself, I cannot use the Time class from Ruby.
Try this as it should return the time back.
puts conn.exec("EXPLAIN ANALYZE SELECT * FROM some_table").values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With