Wednesday, October 18, 2017

Create Django QuerySet from Orcale table-valued Function

Hi,

I try to create a Django QuerySet from an Oracle table-valued Function using the Models raw method:


XX.objects.raw("SELECT 1 as id, PROJEKT FROM TABLE(my_table_function())")




As soon as I evaluate the query set (access a model property)I get the error:

django.db.utils.DatabaseError: ORA-00942: table or view does not exist


After some debugging I figured out that Django adds a table name to the SQL statement when evaluating the QerySet including an Oracle table function:


XX.objects.raw("SELECT 1 as id, PROJEKT FROM TABLE(my_table_function())")

becomes


SELECT
"CHARTS_XX"."ID", "CHARTS_XX"."PROJEKT" FROM "CHARTS_XX" WHERE CHARTS_XX"."ID" = %s


where "charts" is my app name and "XX" my Model.

Is there any way to force Django tu use the table function?


I have tested the table function using a SQL shell withour any problems.


Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4e93d46e-5865-4d4a-8a39-a28540f2d458%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment