On Tuesday 21 October 2014 18:23:44 Chris Foresman wrote:
> Is there some benefit to using `.callproc()` over this?
> 
> ``` python
>     query = 'CALL sp_recommendation_engine(%s, %s)'
>     profile = user.get_profile()
>     cursor = connection.cursor()
>     cursor.execute(query, [user.id, profile.id])
> ```
> 
There are two benefits:

1) Unlike Python functions, SQL stored procedures can have output parameters 
(and input/output parameters). callproc() allows you to get these (it returns 
the sequence of parameters, with outputs placed appropriately), while 
execute() can only return the procedure's return value (I'm not quite sure 
about procedures yielding result-sets -- callproc() will let you fetch the 
results, I'm not sure the same holds for execute() universally).

2) Surprisingly, stored procedure invocation syntax is not completely 
standard; for example, on PostgreSQL, you should have

        query= 'SELECT sp_recommendation_engine(%s, %s)'

HTH,
        Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/201410220044.07534.shai%40platonix.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to