Formatting data array with ruby -


i trying data postgresql ruby , store them array, have small script:

script :

require 'pg'    conn=pgconn.connect( :hostaddr=>"192.168.111.136", :port=>5432, :dbname=>"sentinel_poc",:user=>"sdn_mehdi", :password=>'skyline123')    res = conn.exec("select dns_name dns_table group dns_name").to_a    a_dns = []    res.each { |r| a_dns << r }   puts a_dns.join(",")   

the outcome :

{"dns_name"=>"youtube.com                                       "},{"dns_name"=>"stackoverflow.com                                         "},{"dns_name"=>"cisco.com                                         "},{"dns_name"=>"facebook.com                                      "},{"dns_name"=>"yahoo.com                                         "},{"dns_name"=>"onf.com                                           "},{"dns_name"=>"safe.com                                          "},{"dns_name"=>"linkedin.com                                      "},{"dns_name"=>"amazon.com                                        "},{"dns_name"=>"google.com                                        "},{"dns_name"=>"java.com                                          "},{"dns_name"=>"live.com                                          "},{"dns_name"=>"rails.com                                         "},{"dns_name"=>"postgresql.com                                    "},{"dns_name"=>"hp.com                                            "},{"dns_name"=>"wikipedia.org                                     "} 

what need name of each domain name! {"youtube.com","google.com","java.com","rails.com","hp.com"}

any suggestions appreciated.

taking code only, , doing small changes, guess following work you

a_dns = []    res.each { |r| a_dns << r.values[0].strip }   puts a_dns 

Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -