arrays - SQLAlchemy(Postgres)ARRAY 与 JSON 的整数列表
问题描述
我想使用 SQLAlchemy(使用 Postgres)将整数列表存储在 Column 中。
我最好使用 ARRAY 还是 JSON?我的猜测是 ARRAY 在这种情况下会有更好的性能,但我没有看到任何在线确认。
附加问题:如果我希望整数是唯一的怎么办?
解决方案
PostgreSQL collects statistics on array membership for PostgreSQL arrays, but not for JSON arrays. This often leads to much better performance. Plus PostgreSQL arrays are typed, which seems like a benefit for your case.
Additional question: What if I want the integers to be unique?
Can you expand on that? You want it to throw an error if you try to add a second copy of any one element? Silently ignore the addition? (Although neither case has in-place additions, it is really an assignment of the new array/JSONB which has happens to have one more element than the old one).
推荐阅读
- android - 当我打开搜索项时,它打开的是 ListView 的第一项而不是搜索项。即使搜索并找到项目成功
- angular - 如何在 Angular 中使用 concatMap 避免嵌套订阅
- c# - How send content body in Http Request with GET method in .Net
- c++ - wxWidgets 3.1.4 native on M1 get setup.h missing
- assembly - Conditional move (cmov) for AVX vector registers based on scalar integer condition?
- powershell - REG EXPORT 单个值到 .reg 文件
- azure-ad-b2c - 如何邀请来宾用户加入 Azure B2C 平台并向他们提供对应用程序的访问权限?
- java - “标记“else”的语法错误,删除此标记”(Java)
- makefile - 子制作多次运行相同的规则
- git - 在 git 中决定默认远程(默认为整个项目,而不是每个分支)