如何在Sqlite3的一列中存储数组? [英] How to store array in one column in Sqlite3?

查看:152
本文介绍了如何在Sqlite3的一列中存储数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在表的一列中存储整数数组?我想要o / p这样:

Is there any way to store an array of integers in one column of table? I want o/p like this:

ident | value                                                            | count 
----------------+------------------------------------------------------------------------------------------------------------------------+-------
563 | [0:10]={"(0,0)","(1,100)","(2,200)","(3,300)","(4,400)","(5,500)"} |    6

这个我已经通过postgres实现,但我想从sqlite同样o / p。
这里的列值存储一个数组。我尝试通过BLOB,但它不工作。有人告诉我有关序列化的方式,但我不知道该怎么做。

This I have already acheieved through postgres but i want same o/p from sqlite also. Here column value store an array. I tried it through BLOB but it is not working. Somebody told me about serialized way but i am not sure how to do that.

推荐答案

SQLite3不支持数组。请参见此处其支持的类型。基本上,它只有Ints,Floats和Text。

SQLite3 does not support arrays directly. See here the type it supports. Basically, it only does Ints, Floats and Text.

要完成您所需要的,您必须使用自定义编码,或使用FK,即创建另一个表,其中数组中的每个项目都存储为一行。

To accomplish what you need, you have to use a custom encoding, or use an FK, i.e. create another table, where each item in the array is stored as a row.

这篇关于如何在Sqlite3的一列中存储数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆