A
A
Alexey2020-04-30 14:06:50
PostgreSQL
Alexey, 2020-04-30 14:06:50

How to use Postgres stored procedures in Django?

Hello! Does anyone know if there is some way to wrap a stored procedure in a Django model?
To make it possible to use paginator, filter (pass parameters to a function) and other joys?
The fact is that the project has statistics that are now calculated through the view, it is wrapped by the model and everything works as it should.
There is a task to make through procedure, there through parameters it is necessary to transfer fields for a filtration.
Or maybe there is some other way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galaxy, 2020-04-30
@galaxy

It will be necessary to call through pure SQL , tk. django will still put the filtering conditions in WHERE, and not in the procedure parameters, and Postgres will not be able to throw them inside (more precisely, if the function is in sql, under certain conditions it can be able to). Yes, and django will not put brackets in the SELECT * from my_proc () call.
And so, you make a function that returns table and should work.

V
Vadim Shatalov, 2020-04-30
@netpastor

Not sure, but you can try via extra
https://docs.djangoproject.com/en/3.0/ref/models/q...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question