E
E
ellz2019-03-05 11:31:02
Django
ellz, 2019-03-05 11:31:02

How to call postgresql function from django with parameter passing?

There is such a function in views.py:

def getNearestNotes(request, longitude, latitude):
  if request.method == 'GET':
    #вызов функции
    return HttpResponse('')
  else:
    return HttpResponse('needGetMethod')

How to call a stored procedure (function) from the postgersql database, passing parameters to it, and then adding the response to the object? DB connected. Everything is working.
I looked for solutions on the Internet, but it seems to me that it’s not at all what I need.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-03-05
@ellz

from django.db import connection

some_arg = 42

c = connection.cursor()
try:
    c.callproc('some_stored_procedure', (some_arg,))
    r = c.fetchone()
    ...
finally:
    c.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question