Good points. I went looking for `callproc()` documentation and couldn't find anything useful, which if I understand correctly is part of the reason this thread started. So +1 on documenting it!
The most complicated part of dealing with store procedures from a high level is getting them in the database to begin with, and updating them if they need to change. Obviously I'm just manually entering them via the console, but it would be great if there was some consistent way to add them to the database via Migrations or something similar. On Tuesday, October 21, 2014 4:44:25 PM UTC-5, Shai Berger wrote: > > 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/4ec3adbe-e240-4a80-bd8e-1f8a8eb5d229%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
