Determining correct data type of a Ruby object

12 views
Skip to first unread message

Derek S

unread,
Mar 18, 2015, 7:00:51 PM3/18/15
to rub...@googlegroups.com
I'm not entirely sure how to do this from the documentation.

I have a variable in Ruby,

num = 12345.89

and I would like to return the correct Postgresql data type so as to create the correct table for it:

datatype = type(num)
res = conn.exec("create table company(salary #{datatype})")

What is the right syntax for this?

Thanks,
Derek


Lars Kanis

unread,
Mar 19, 2015, 10:35:50 AM3/19/15
to rub...@googlegroups.com
2015-03-19 0:00 GMT+01:00 Derek S <terrawa...@gmail.com>:
and I would like to return the correct Postgresql data type so as to create the correct table for it:

datatype = type(num)

There is no such thing in pg. Type mapping is often ambiguous, so that pg does not mandate a particular mapping. You could use some higher level library like http://datamapper.org/ for this job, but most people prefer to explicitly define their SQL column types in one or another way.

--
Regards,
Lars
Reply all
Reply to author
Forward
0 new messages