'pg' gem の最新バージョンが db クエリ列の結果をランダムな順序で返すのは正常ですか? 「pg」gem は mysql2 gem と同じように動作し、コマンド ラインから直接データベースにクエリを実行したときに提示された順序でデータを返すことを期待しています。たぶん、私が使用すべきより良い宝石がそこにあるでしょう。以下の結果の例は、同じクエリ「select * from books」を使用した結果です。
最初の実行:
"The Shining","9","7808","4156"
"Dune","15","4513","1866"
"2001: A Space Odyssey","15","4267","2001"
"The Cat in the Hat","2","1608","1809"
"Bartholomew and the Oobleck","2","1590","1809"
2 回目の実行:
"4156","The Shining","9","7808"
"1866","Dune","15","4513"
"2001","2001: A Space Odyssey","15","4267"
"1809","The Cat in the Hat","2","1608"
"1809","Bartholomew and the Oobleck","2","1590"
3 回目の実行:
"9","The Shining","7808","4156"
"15","Dune","4513","1866"
"15","2001: A Space Odyssey","4267","2001"
"2","The Cat in the Hat","1608","1809"
"2","Bartholomew and the Oobleck","1590","1809"
結果を返すコード:
confrom = PG::Connection.new(:user => <myuser>, :password => <mypw>, :port => 5432, :host => <myhost>, :dbname => 'booktown')
results = confrom.exec("select * from books")
results.each do |row|
row.each_value do |x|
puts x
end
end