postgresql array of [bigint, real]

34 views
Skip to first unread message

jim rosenblum

unread,
Mar 7, 2014, 11:25:43 AM3/7/14
to chica...@googlegroups.com
I am considering a major change to my application and before I do, I was wondering if anyone knew the answer to the following.

I have a model that has an attribute, value, which looks like this
 [[1234959596, 10.23],[1234959596, 10.23],[1234959596, 10.23]]

basically an array of [bigint, float]

Can I do this with ChicagoBoss and postgress?

David Welton

unread,
Mar 7, 2014, 11:33:55 AM3/7/14
to chica...@googlegroups.com
Hi,
The first thing that I would say offhand is that to model that in a
relational way, your model, say, foo, should have a related model
'bar' that has foo_id, bigints and floats. foo should have many bars,
and bars should belong to foo. That would be the 'clean' way of
doing things. Then you could do FooInstance:bars() or create your own
function to return just the array you are interested in.

You might be able to utilize Postgres' arrays too, but the only way to
check is to try it and see - perhaps working up from the Postgres
layer.

--
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/

Graeme Defty

unread,
Mar 7, 2014, 7:42:41 PM3/7/14
to chica...@googlegroups.com
Hi Jim,

I had a similar situation in my app but my attribute was much simpler - an array of Ints. I knew there was nothing in the Mnesia driver to prevent it (and of course Mnesia itself will happily store any Erlang form as a value) but I was pleased to discover that nothing in the rest of CB prevented it. Perhaps it is being viewed as a character string.

In any case - unless someone comes back and says "Oh yes - I do that all the time with Postgress and it works fine"  I would suggest writing a little test app to check it for yourself. You could do it in no time and move on with the confidence of knowing it works.

graeme



--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/df61a3f2-beaf-4c92-b4d8-97ecd8857668%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jim rosenblum

unread,
Mar 7, 2014, 7:50:49 PM3/7/14
to chica...@googlegroups.com
Thanks everyone for your replies. By the way, my need is that I am denormalizing some time-series data so that I can more efficiently return it to a JavaScript front-end graphing API.

I decided to encode the array of arrays as binary (term_to_binary) which gets stored in a bytea column in Postgres.

Works great.

Graeme Defty

unread,
Mar 7, 2014, 7:57:33 PM3/7/14
to chica...@googlegroups.com
Hi Jim,

Yes mine was a similar situation where the list of numbers really WAS just a lits of numbers with no other attributes associated with the things they represented. I agonised long and hard over normalising it further, as David suggested, but in the end decided against it.

Glad it worked OK for you (and thanks for the update)

Just dont expect CB Admin to like it much!  (I am guessing that like me you are not using Admin)

Cheers,

g



--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
Reply all
Reply to author
Forward
0 new messages