我無法從pg gem中獲得輸入結果。pg gem:'Warning:沒有爲類型「numeric」定義類型轉換''
require 'pg'
require_relative 'spec/fixtures/database'
client = PG.connect(DB[:pg])
client.type_map_for_queries = PG::BasicTypeMapForQueries.new(client)
client.type_map_for_results = PG::BasicTypeMapForResults.new(client)
client.exec(%|select * from testme;|) do |query|
query.each {|r| puts r.inspect }
end
這個節目給輸出:
Warning: no type cast defined for type "money" with oid 790. Please cast this type explicitly to TEXT to be safe for future changes.
Warning: no type cast defined for type "numeric" with oid 1700. Please cast this type explicitly to TEXT to be safe for future changes.
{"string"=>"thing", "logical"=>true, "cash"=>"£1.23", "reel"=>"2.34", "day"=>#<Date: 2015-12-31 ((2457388j,0s,0n),+0s,2299161j)>, "float"=>3.45}
所以:布爾和花車和日期(和整數)被轉換,但不NUMERICS還是把錢類型。
任何人都可以告訴我如何「明確地轉換類型」,假設我不想硬編碼每個表的解決方案?
PS經過這麼多年的潛伏後,我剛加入SO,這是我的第一個貢獻。指導讚賞;) – Giuse
你的代碼中存在一個錯字('new_coder' - >'name_coder'),如果你顯示錯誤信息,它會花費我兩分鐘而不是五分鐘。但沒有任何關係。你已經解決了別人無法做到的事情,即使我提供了賞金。勾選,勾選,勾選。非常感謝! –
我沒有錯誤顯示,因爲我在我的實現中使用了'name_coder'。我的字段實際上被恰當地命名爲'name',因此我選擇了'name_coder',不幸的是在代碼中回聲'c.name' ......困惑了嗎?這就是爲什麼我(試圖)更改名稱的原因:P感謝您發現最後一個名字,我寫了這個答案的那天我幾乎被燒死了。樂意效勞! :) – Giuse