On Sep 1, 2:15 pm, Dave Howell <[email protected]> wrote: > There are a couple of datatypes that Postgres uses that don't come through > Sequel unscathed ("uuid" and "array" to name two), but this one surprised me. > "money" comes back as 0.0, no matter what actual amount is in the database. > > CREATE TABLE tsttbls ( > tsttbl_id uuid DEFAULT uuid_generate_v1() NOT NULL, > note varchar, > fee money, > PRIMARY KEY (tsttbl_id) > ); > > insert into tsttbls(note, fee) values('Lunch', '23.50'::money); > insert into tsttbls(note, fee) values('Taxicab', '35.00'::money); > > >> class Tsttbl < Sequel::Model end > >> t = Tsttbl.first > >> puts "#{t.note}\t #{t.fee}" > > Lunch 0.0 > > >> pp Tsttbl.select(:fee).all > > [#<Tsttbl @values={:fee=>#<BigDecimal:10201fce0,'0.0',4(4)>}>, > #<Tsttbl @values={:fee=>#<BigDecimal:10201fa10,'0.0',4(4)>}>]
See http://www.postgresql.org/docs/8.3/static/datatype-money.html Note the part about "here is no simple way of doing the reverse in a locale-independent manner, namely casting a money value to a numeric type." Now, you could try: Sequel::Postgres::PG_TYPES[790] = lambda{|v| BigDecimal.new(v[1..-1])} Assuming that you are in a locale where money is displayed as $DD.DD, that should work. If you have any control over the schema, use a numeric type such as numeric(10,2) instead of money. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
