database/sql : i have a need to use postgresql numeric column data type for currency / money value processing

1,035 views
Skip to first unread message

evan

unread,
Jan 7, 2018, 10:29:51 AM1/7/18
to golang-nuts
c# has a decimal type that i can map my numeric(12,2) column data type to, but golang doesnt have a decimal type.

i'm trying to avoid storing money values as cents then converting them to dollar values when needed, and
also would like to stay close to using database/sql's standard API as much as possible.

would i be able to meet these needs  by maybe using https://godoc.org/github.com/lib/pq for most of my needs, 
and then maybe using pgx's custom Decimal / Numeric type (https://godoc.org/github.com/jackc/pgx/pgtype)
to facilitate currency value processing?  

could anybody with experience doing something like this share their experience(s) and suggestion(s) with me? 

thank you for helping!

matthe...@gmail.com

unread,
Jan 7, 2018, 10:57:58 AM1/7/18
to golang-nuts
Why avoid using a bigint column storing cents?

Matt

Alex Rice

unread,
Jan 8, 2018, 12:23:29 AM1/8/18
to golang-nuts
An interesting question (I am just learning Go).
Anyways I found this- maybe relevant for you:

https://github.com/shopspring/decimal


Andy Balholm

unread,
Jan 8, 2018, 9:52:12 AM1/8/18
to evan, golang-nuts
If all the calculations are going to be in the database, you can just use strings on the Go side.

Andy

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages