1
最新版'pg'gem以隨機順序返回db查詢列的結果是否正常?我希望'pg'gem的行爲與mysql2 gem的行爲相同,當通過命令行直接查詢數據庫時,它會按照它呈現的順序返回數據。也許我應該使用更好的寶石。下面我結果的這個例子是期運用同樣的查詢結果 「選擇從書本*」PG gem以隨機順序返回列
第一次執行:
"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"
第二次執行:
"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"
第三個執行:
"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
完美。非常感謝您花時間回覆。 select語句只是爲了得到一些返回的數據,但我一定會聽到你的警告和我的生產語句。 –