[Django]-Django ORM vs PostgreSQL raw SQL


Using a raw query will result in close to no performance difference. The ORM indeed uses a few cycles to construct the query, but that is insignificant compared to the work of sending the query, the database receiving, interpreting and running the query, and sending the results back.

In some cases the ORM might indeed make a (over)complicated query, but that is not the case if you fetch all records. It sometimes requires ORM expertise (just like it requires expertise in SQL) to find a query that performs better.

You can furthermore already let the Django ORM do the work for you by using .values() to make it more convenient to construct a DataFrame:

res = pd.DataFrame(table_name.objects.values())

Leave a comment