在postgresql中,django模型如何在text []之后 [英] how does django model after text[] in postgresql

查看:154
本文介绍了在postgresql中,django模型如何在text []之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何映射Django ORM中的PostgreSQL数组字段

我有一个表格,其中一个列的数据类型文本[]在Postgresql中。我可以知道如何使用django模型orm访问此列?我知道这是一个commaseparatedintegerfield,但没有这样的文本相关领域。我是否使用textfield或者需要为此创建自定义字段?

I have a table wit one of the columns of datatype text[] in postgresql. May I know how do I access this column using django models orm? I'm aware that theres a commaseparatedintegerfield, but no such for text related fields. Do i use textfield or need to create a custom field for this?

推荐答案

我不认为Django ORM支持PostgreSQL数组。这是不奇怪的,因为这看起来像一个相当PostgreSQL的功能。如果你真的要使用数组,最好的办法是用手工构造SQL查询。否则,正如马克建议的那样,将数组列转成表格。这是迄今为止更便携和概念上清洁的解决方案(尽管性能可能会降低)。

I don't think Django ORM supports PostgreSQL arrays. It's unsurprising, as this looks like a fairly PostgreSQL-specific feature. If you really have to use arrays, your best bet is to construct SQL queries as text by hand. Otherwise, just turn the array columns into tables, as Mark suggests; that is by far a more portable and conceptually clean solution (although the performance may be lower).

这篇关于在postgresql中,django模型如何在text []之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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