I have a ruby script where I need to retrieve all values from a database and do stuff with each one retrieved. Currently I am hard coding each retrieval, but this only works if there are 3 values coming back. How can I iterate over this? Below is my code:
require 'pg'
pg_conn = PGconn.connect(host = "main-pg-db-super.center.com", port = 6433, options = '', tty = '',
dbname = "master_data", login = "user", password = "password")
all_children = pg_conn.exec("SELECT id FROM pt.tests WHERE parent = '1';") # will return 3 results
puts all_children[0]['id']
puts all_children[1]['id']
puts all_children[2]['id']
all_children.each do |child|
puts child['id']
end
Does this not work?
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