[英]How can I write this sql query in django orm?
I have a sql query that works like this, but I couldn't figure out how to write this query in django. Can you help me?我有一个像这样工作的 sql 查询,但我不知道如何在 django 中编写这个查询。你能帮帮我吗?
select datetime,
array_to_json(array_agg(json_build_object(parameter, raw))) as parameters
from dbp_istasyondata
group by 1
order by 1;
You can use raw
function of django orm. You can write your query like this:您可以使用
raw
的 function of django orm。您可以这样编写查询:
YourModel.objects.raw('select * from your table'): #---> Change the model name and query
Here you have PostgreSQL system functions.这里有 PostgreSQL 个系统函数。 Django ORM doesn't have all these functions.
Django ORM 没有所有这些功能。 Django ORM can cover it partially.
Django ORM 可以部分覆盖。
Now you can do one of these.现在你可以做其中之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.