Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

362
Views
Django RAW SQL, named parameters

I have a complex query, with some inner joins, a little where clause and HAVING clause too, this is for a report.

In this case, I can't use Model.objects.raw, so instead, I'm using cursor.execute(sql). My question is with my parameters. I have 20 parameters and some of them are repeated (company_id in every inner join).

Using a dict and %(key)s don't work here when using cursor.execute, it only works with Model.object.raw.

How can I name parameter, to just pass it once? Or is there a method to sanitize my entire query, avoiding SQL injection?

Pass all the 20 parameters and repeating them in order in a list is not readable.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

According to Django documentation this is the right way to do it but WARNING it won't work on Sqlite

cursor.execute('SELECT * from Bla where id = %(some_id)s', {"some_id":1})
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!